how can i test the below snippet using jest. I am trying to test the winston custom format the printf
// sample.js
import {aa:{b}} = require(\"thirparty-packa
If it's b
that needs to be tested then it should be a spy, not a
.
Third-party module should be mocked (a demo):
const bMock = jest.fn();
jest.mock('thirparty-package', () => ({ aa: { b: bMock } }));
const { a } = require('./sample');
a();
const callback = bMock.mock.calls[0][0];
expect(callback).toEqual(expect.any(Function));
expect(callback({ message: 'foo' })).toBe('log message will be foo');