In a few places we're asserting that console logging is called, which requires a bit of finesse to properly temporarily disable ESLint rules and reset mock calls (in order to avoid tripping the global unintended console logging assertions):
We should plan to refactor these into a custom Jest matcher.
Possible usage:
// expect( console ).toHaveLogged( [ level[, expectedMessage ] ] );
expect( console ).toHaveLogged( 'warn', 'Should not do that!' );
expect( console ).toHaveLogged( 'error', 'Cannot do that!' );
See: https://facebook.github.io/jest/docs/en/expect.html#expectextendmatchers
I expect this would be something that is useful to the wider JavaScript community. Is this something to contribute to Jest?
@atimmer It's not really broadly applicable, since it's in our setup that there's a spy for console logging which is globally asserted to not have been called, which is valuable but adds complexity to _expecting_ the logging.
Nice idea. Let鈥檚 do it!
I have shared a proof of concept with #4285. Let me know if it meets your expectations :)
Most helpful comment
@atimmer It's not really broadly applicable, since it's in our setup that there's a spy for console logging which is globally asserted to not have been called, which is valuable but adds complexity to _expecting_ the logging.
https://github.com/WordPress/gutenberg/blob/eb7b0b771924c6d0cae2cc001e7790caf8bfe9c6/test/unit/setup-test-framework.js#L25-L37