nishimura.clubnishimura.club

Jest実行時にconsole仕込んで、変数の中身を確認したい

作成日
2022-04-13
更新日
2022-04-13

問題

Jestでconsoleを出力させたい。

Jest Runnerで実行している

Jest Runner - Visual Studio Marketplace入れる。

settings.json
"jestrunner.jestCommand": "yarn test"

調査

jestjs - Console.log statements output nothing at all in Jest - Stack Overflow

console.logが表示されないのは、モックされているからみたい。

One of the potential reason that logging is not printing is due to console.log has been mocked. Something as below

// jest-setup.js global.console = { // eslint-disable-next-line no-undef log: jest.fn(), // console.log are ignored in tests // log: console.log, // Keep native behaviour for other methods, use those to print out things in your own tests, not `console.log` error: console.error, warn: console.warn, info: console.info, debug: console.debug, };

解決策

console.infoなどのjestでモックされていない関数を使う。

Related

Tags

Jest

Share

Table of Contents