diff --git a/.changeset/calm-files-sort.md b/.changeset/calm-files-sort.md new file mode 100644 index 0000000000..a487c00eb4 --- /dev/null +++ b/.changeset/calm-files-sort.md @@ -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. diff --git a/packages/backend-plugin-api/src/wiring/factories.test.ts b/packages/backend-plugin-api/src/wiring/factories.test.ts index 1fd05a1605..9f11c9b40b 100644 --- a/packages/backend-plugin-api/src/wiring/factories.test.ts +++ b/packages/backend-plugin-api/src/wiring/factories.test.ts @@ -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}'); }); }); diff --git a/packages/backend-plugin-api/src/wiring/factories.ts b/packages/backend-plugin-api/src/wiring/factories.ts index d0199e775a..5442bab897 100644 --- a/packages/backend-plugin-api/src/wiring/factories.ts +++ b/packages/backend-plugin-api/src/wiring/factories.ts @@ -51,6 +51,10 @@ export function createExtensionPoint( 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() {