Closed maplion closed 4 years ago
It looks like there's some issue with the
it('should correctly call `PING` on WebSocket', fakeAsync(() => {
const type = 'WEBSOCKET::PING';
const action$ = of({ type });
const epic$ = webSocketEpics.pingMessageEpic(action$);
epic$.subscribe((action: AnyAction) => {
// console.log(action);
expect(action.type).toBe('WEBSOCKET::PING_MESSAGE_SENT');
expect(action.payload).toEqual({action: 'ping'});
tick(100);
});
}));
unit test. According to the provided log, the test produces 2 errors:
Error: 1 timer(s) still in the queue.
when it runs initially, and
TypeError: Cannot read property 'pipe' of undefined
at new AppService (C:\\git\\geocomm\\gc-maps-frontend\\src\\app\\core\\services\\app.service.ts:24:14)
on your changes inside it.
something working that works in Jest
Are you sure that your test actually works in Jest CLI? If you change your test as follows:
epic$.subscribe((action: AnyAction) => {
throw new Error('expected error');
// console.log(action);
//expect(action.type).toBe('WEBSOCKET::PING_MESSAGE_SENT');
//expect(action.payload).toEqual({action: 'ping'});
tick(100);
});
does Jest display the thrown error?
Back to the errors, according to the post, this error
Error: 1 timer(s) still in the queue.
is thrown by zone.js
when some “timers” (=setTimeouts) in the queue
. My guess would be that your test never calls epic$.subscribe
subscription action (neither in Jest nor in Wallaby, it's just that maybe Wallaby reports it, while Jest doesn't). Try something like:
epic$.subscribe((action: AnyAction) => {
// console.log(action);
expect(action.type).toBe('WEBSOCKET::PING_MESSAGE_SENT');
expect(action.payload).toEqual({action: 'ping'});
tick(100);
});
+ tick(1000);
If it doesn't help, or my assumptions are incorrect, please create a sample repo where we could reproduce the issue, we are happy to investigate it.
@ArtemGovorov Thank you for the response. I tried to redo my janky code to try to better isolate the problem and continue my learning process with this. I tried your suggestion and it did not make a difference. There seemed to be two main issues:
Issue description or question
I am attempting to create tests for redux-observable epics within Angular, utilizing Jest 24.9.0. While I have struggled to figure out the proper way to mock dependencies and get the setup right, I finally got something working that works in Jest, but Wallaby shows me pink squares (but no red squares), starting with spectator_AppService = createService_AppService() in my beforeEach() function. If there is some insightful information the testing gurus could share with me, that would be nice, but here is my describe setup; the pink squares start with the first beforeEach declaration (and my entire test is pink squares except the "it" line):
Wallaby diagnostics report