refactor: set extenstion point "t" to null
Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user