Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest obsolete snapshot warning causes test failure: ignore warnings when exiting Jest

I have a test suite/file that I have disabled. It has an associated snapshot file. For my particular situation I do not want to delete or update the snapshot file (long-story-short: it is used elsewhere).

So, Jest logs out just a warning, rather than a failure, for the obsolete snapshot. However Jest then exits with code 1 and my build fails. This happens despite no test actually failing.

Can I tweek the config to ignore obsolete snapshots? Or is there some other way to have Jest exit with code 0 after only a warning?

enter image description here

like image 459
cham Avatar asked Jun 19 '20 00:06

cham


People also ask

What is obsolete snapshot?

"Obsolete" refers to snapshots or snapshot files, for which no . toMatchSnapshot() exists any more. Snapshots are organised in one file per test suite. Single snapshots in those files are stored along with the name of their test, given in jest's it() function.

How do you exit jest test?

--forceExit ​ Force Jest to exit after all tests have completed running. This is useful when resources set up by test code cannot be adequately cleaned up. This feature is an escape-hatch.

Is snapshot testing is supported in jest?

Jest has been rewritten with performance in mind, and snapshot testing is not an exception. Since snapshots are stored within text files, this way of testing is fast and reliable. Jest generates a new file for each test file that invokes the toMatchSnapshot matcher.

What is a jest snapshot?

Jest is a popular framework for testing JavaScript, and Jest snapshot is a method for creating an HTML entity map for regression tests. Ideally, a developer can create a jest snapshot for each output\component and create a test that easily compares it in each run. If any change is detected, the test fails.


1 Answers

Add --silent to your test-ui script in the projects package.json

like image 83
Mario Perez Avatar answered Oct 19 '22 03:10

Mario Perez