Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get total count of assertions made in a React app using Jest

I am currently using the built-in Jest testing environment that comes with the generated boilerplate by create-react-app. With Jest's integration with Istanbul, one can get the unit test coverage by total number of statements, functions, lines, and branches covered. Aside from these, is there any way to get the total number of assertions used in all the unit test files? Thanks!

like image 452
sdabrutas Avatar asked Oct 13 '25 03:10

sdabrutas


1 Answers

I'm not aware if jest has this functionality built in, but we can probably mimic this with grep and wc.

Grep searches files for specific text.

 grep [options] PATTERN [FILE...]

 -r --recursive
 -c --count
 -i --ignore-case
 --include=PATTERN
   Recurse in directories only searching file matching PATTERN.

wc - print newline, word, and byte counts for each file

wc [OPTION]... [FILE]...

-l, --lines
print the newline counts

Print the count of "expect" pattern matches in each file:

grep -r -i -c --include \*.test.js "expect" . matches

Print the sum of total "expect" pattern matches.

grep -r -i --include \*.test.js "expect" . | wc - l