How to perform checks after expect().toBeObservable() ?
See original GitHub issueBack when I was using karma with jasmine-marbles I could write tests like this:
expect(result).toBeObservable(expected);
expect(mockInsideObservable).toHaveBeenCalled();
Which is easy to read and write. The main thing here is that expect.toBeObservable acts synchronously and waits for all the code inside the observable to be executed.
The same code in jest and jest-marbles will always fail with the following message:
Expected mock function to have been called, but it was not called
Because the last assertion is evaluated before the observable. Is this expected behavior? If so, would it be possible to provide some sort of promise or callback to the observable assertion?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
How to test Observables. The ultimate guide - Medium
If the last item would be emitted after 20 seconds instead of 3? Our test would fail. So that's no solution. We don't...
Read more >Testing Observables with jest - rxjs - Stack Overflow
it('should do the job', async () => { await expect(myObservable .pipe(first()) .toPromise()) .resolves.toEqual(yourExpectation); });.
Read more >Testing Observables in Angular - Netanel Basal
When we run detectChanges() , the ngOnInit() hook will run and execute the subscription function synchronously, causing the isLoading property to always be ......
Read more >How to Test Five Common NgRx Effect Patterns
initialiseComplete(), }); expect(effects.initialiseThing$).toBeObservable(expected); });. This shows ...
Read more >NgRx Testing: Components | Brian F Love
toBeObservable (expected); }); });. We want to test both the dispatch() and pipe() methods that are invoked in the ngOnInit() ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please use
toSatisfyOnFlush
, available since 2.5.0.Let me know if that helps.
Currently it works in a way that the scheduler is being flashed after each test, therefore your observable is essentially invoked in
afterEach
.I agree it should change and work in the same way
jasmine-marbles
work.Until it is implemented please use the workaround provided above.