Last active
May 3, 2018 04:55
-
-
Save Tallyb/2f21e4c166f4352a7c1fde7c2df4e112 to your computer and use it in GitHub Desktop.
Observable error problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//update: Adding async on the subscribe does the trick... | |
it('should call observable', () => { | |
let mockFn = jest.fn(); | |
mockFn.mockImplementation(() => { | |
return of(4) | |
}); | |
mockFn().subscribe(async (res) => { | |
console.log('RES', res); // it logs 4 | |
await expect(res).toEqual(8); | |
}); | |
}); | |
// | |
//This one will pass | |
// | |
it('should call observable', () => { | |
let mockFn = jest.fn(); | |
mockFn.mockImplementation(() => { | |
return of (4) | |
}); | |
mockFn().subscribe(res => { | |
console.log('RES', res); // it logs 4 | |
expect(res).toEqual(8); | |
}); | |
}); | |
// | |
//this one will fail correctly | |
// | |
it('should call observable', () => { | |
let result; | |
let mockFn = jest.fn(); | |
mockFn.mockImplementation(() => { | |
return of (4) | |
}); | |
console.log('I am before') | |
mockFn().subscribe(res => { | |
console.log('RES', res); | |
result = res; | |
}); | |
expect(result).toEqual(8); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment