refactor: set extenstion point "t" to null

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2024-06-11 09:36:58 +02:00
parent 9caeec3ef1
commit 9bdc3e89ab
3 changed files with 10 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-plugin-api': patch
---
In tests, return `null` rather than throwing an error when trying to get the `ExtensionPoint.T` property, so that tests asserting the property are not easily broken.
@@ -26,7 +26,7 @@ describe('createExtensionPoint', () => {
const extensionPoint = createExtensionPoint({ id: 'x' });
expect(extensionPoint).toBeDefined();
expect(extensionPoint.id).toBe('x');
expect(() => extensionPoint.T).toThrow();
expect(() => extensionPoint.T).not.toThrow();
expect(String(extensionPoint)).toBe('extensionPoint{x}');
});
});
@@ -51,6 +51,10 @@ export function createExtensionPoint<T>(
return {
id: options.id,
get T(): T {
if (process.env.NODE_ENV === 'test') {
// Avoid throwing errors so tests asserting extensions' properties cannot be easily broken
return null as T;
}
throw new Error(`tried to read ExtensionPoint.T of ${this}`);
},
toString() {