Skip to content

Commit 441011d

Browse files
committed
docs: improve mock logger sample
This is just a simple improvement in the docs so the example we use to mock logger also covers cases where the developer invoked Logger constructor in their code.
1 parent dc16323 commit 441011d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/logger/README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,17 @@ jest.mock('@dotcom-reliability-kit/logger');
616616
This is because, in order to mock the logger, Jest will still load the original module which creates a fully fledged logger with bindings to `process.stdout`. You can get around this by providing your own manual mock logger, either as a second argument to `jest.mock` or as a file in `__mocks__/@dotcom-reliability-kit/logger.js`. E.g.
617617
618618
```js
619+
const mockedLogger = {
620+
debug: jest.fn(),
621+
error: jest.fn(),
622+
fatal: jest.fn(),
623+
info: jest.fn(),
624+
warn: jest.fn(),
625+
};
626+
619627
jest.mock('@dotcom-reliability-kit/logger', () => ({
620-
debug: jest.fn(),
621-
error: jest.fn(),
622-
fatal: jest.fn(),
623-
info: jest.fn(),
624-
warn: jest.fn()
628+
...mockedLogger,
629+
Logger: jest.fn(() => mockedLogger),
625630
}));
626631
```
627632

0 commit comments

Comments
 (0)