I have a code in React
$.get('/bin/data', (response) => { this.data = response; });
This is my test case:
$document = { on: jest.fn().mockName('$document.on'), }; expect(window.$).toBeUndefined(); $ = jest.fn().mockName('$').mockReturnValue($document); $.get = () => {}; jest.spyOn($, 'get').mockName('$.get').mockImplementation(response => jest.fn()); // not sure what to do here such that callback function is also covered window.$ = $;
Everything is working fine, but the callback function is not getting covered.
Got if solved.
jest.spyOn($, 'get').mockName('$.get').mockImplementation((url, myMockFn) => { myMockFn({ name: 'Tom' }); });
1.4m articles
1.4m replys
5 comments
57.0k users