Consider the following code snippet which defines a function that returns an observable :
retrieveAll = (): Observable<Well[]> =>
from(this.wellRepository.retrieveAssets()).pipe(
map((assets: Asset[]) => this.mapper.mapping(assets)),
catchError(() => {
throw new Error("Something went wrong");
})
);
I attempted to test this function in the following way :
describe("Api Well Repository", () => {
it("should retrieve wells", (done) => {
const apiWellRepository = new ApiWellRepository(
new InMemoryWellRepository()
);
const observable$: Observable<Well[]> = apiWellRepository.retrieveAll();
observable$.subscribe((wells: Well[]) =>
expect(wells).toStrictEqual([
{
id: "1",
name: "Angola_0",
},
])
);
});
});
The InMemoryWellRepository class provides an async array data source :
export class InMemoryWellRepository {
private readonly assets: Asset[] = [
{
id: "1",
name: "Angola",
},
];
retrieveAssets = async (): Promise<Asset[]> => this.assets;
}
This testing scenario fails due to a timeout issue.
If deliberately expecting an incorrect output, the test also results in a timeout error with a message indicating a failure in deep equality comparison. While the test appears to be functioning correctly, it seems to encounter difficulties completing and ends up timing out.