A Karma framework for using some of Jest's best features in a browser.
npm i karma-jest -D
Or with yarn
yarn add karma-jest -D
In your karma config:
module.exports = (config) => {
config.set({
// add your test files
files: ['test/**/*.test.js'],
plugins: ['karma-jest'],
frameworks: ['jest'],
reporters: ['jest'],
// Add options
jest: {
snapshotPath: 'test/__snapshots__',
},
});
};
At the momement there is only one option:
snapshotPath
: the directory snapshots are saved in, defaults to:path.join(karmaConfig.basePath, '__snapshots__')
Because a browser is very different environment from Node, there are a few
key differences with how karma-jest
works compared to Jest.
- Compiling and bundling test files is up to you. Use which ever karam preprocessor
is appropriate for your project, probably
karma-webpack
orkarma-preprocessor-rollup
. - Test's are organized by top level describe blocks instead of test files.
this means
.only
tests apply to the entire test suite, and snapshots are located in a single directory organized by suite name, instead of file name. - module mocking does not work! You can use something specific to your preprocessor if you need.