UNPKG

@wordpress/jest-console

Version:
43 lines (39 loc) 1.14 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); require("./matchers"); var _supportedMatchers = _interopRequireDefault(require("./supported-matchers")); /** * Internal dependencies */ /** * Sets spy on the console object's method to make it possible to fail test when method called without assertion. * * @param args */ const setConsoleMethodSpy = args => { const [methodName, matcherName] = args; const spy = jest.spyOn(console, methodName).mockName(`console.${methodName}`); /** * Resets the spy to its initial state. */ function resetSpy() { spy.mockReset(); spy.assertionsNumber = 0; } /** * Verifies that the spy has only been called if expected. */ function assertExpectedCalls() { if (spy.assertionsNumber === 0 && spy.mock.calls.length > 0) { expect(console).not[matcherName](); } } beforeAll(resetSpy); beforeEach(() => { assertExpectedCalls(); resetSpy(); }); afterEach(assertExpectedCalls); }; Object.entries(_supportedMatchers.default).forEach(setConsoleMethodSpy); //# sourceMappingURL=index.js.map