diff --git a/.changeset/chatty-books-buy.md b/.changeset/chatty-books-buy.md new file mode 100644 index 0000000000..5cf8083bf7 --- /dev/null +++ b/.changeset/chatty-books-buy.md @@ -0,0 +1,13 @@ +--- +'@backstage/core-api': patch +--- + +Updated the `Observable` type to provide interoperability with `Symbol.observable`, making it compatible with at least `zen-observable` and `RxJS 7`. + +In cases where this change breaks tests that mocked the `Observable` type, the following addition to the mock should fix the breakage: + +```ts + [Symbol.observable]() { + return this; + }, +``` diff --git a/.changeset/sweet-colts-teach.md b/.changeset/sweet-colts-teach.md new file mode 100644 index 0000000000..863c90eaa3 --- /dev/null +++ b/.changeset/sweet-colts-teach.md @@ -0,0 +1,5 @@ +--- +'@backstage/test-utils': patch +--- + +Updated `MockErrorApi` to work with new `Observable` type in `@backstage/core`. diff --git a/packages/core-api/src/lib/subjects.ts b/packages/core-api/src/lib/subjects.ts index 9ebde6ebbc..5239e460af 100644 --- a/packages/core-api/src/lib/subjects.ts +++ b/packages/core-api/src/lib/subjects.ts @@ -53,6 +53,10 @@ export class PublishSubject ZenObservable.SubscriptionObserver >(); + [Symbol.observable]() { + return this; + } + get closed() { return this.isClosed; } @@ -148,6 +152,10 @@ export class BehaviorSubject ZenObservable.SubscriptionObserver >(); + [Symbol.observable]() { + return this; + } + get closed() { return this.isClosed; } diff --git a/packages/core-api/src/types.ts b/packages/core-api/src/types.ts index 13a8a72570..8782280be0 100644 --- a/packages/core-api/src/types.ts +++ b/packages/core-api/src/types.ts @@ -39,7 +39,7 @@ export type Subscription = { /** * Value indicating whether the subscription is closed. */ - readonly closed: Boolean; + readonly closed: boolean; }; /** @@ -51,12 +51,14 @@ export type Subscription = { * using many different observable implementations, such as zen-observable or RxJS 5. */ export type Observable = { + [Symbol.observable](): Observable; + /** * Subscribes to this observable to start receiving new values. */ subscribe(observer: Observer): Subscription; subscribe( - onNext: (value: T) => void, + onNext?: (value: T) => void, onError?: (error: Error) => void, onComplete?: () => void, ): Subscription; diff --git a/packages/test-utils/src/testUtils/apis/ErrorApi/MockErrorApi.ts b/packages/test-utils/src/testUtils/apis/ErrorApi/MockErrorApi.ts index 7bf50314d0..b90646201a 100644 --- a/packages/test-utils/src/testUtils/apis/ErrorApi/MockErrorApi.ts +++ b/packages/test-utils/src/testUtils/apis/ErrorApi/MockErrorApi.ts @@ -32,6 +32,10 @@ type Waiter = { const nullObservable = { subscribe: () => ({ unsubscribe: () => {}, closed: true }), + + [Symbol.observable]() { + return this; + }, }; export class MockErrorApi implements ErrorApi {