Encoding not recognized in jest.js

This is problem caused by mysql2 doing dynamic lazy require of encodings and Jest not being able to handle this. Have a look at few workarounds users suggested here:

add this snippet to setupTestFrameworkScriptFile

require('mysql2/node_modules/iconv-lite').encodingExists('foo');

or this somewhere early to your code:

import iconv from 'iconv-lite';
import encodings from 'iconv-lite/encodings';
iconv.encodings = encodings;

Really only need to add:

require('iconv-lite').encodingExists('foo')

to the top of whatever file you're testing such as factory.test.js

Not sure why this is unfortunately, but the above is better for copy / pasting than the chosen answer.