Unit testing Svelte projet in Jest
Install Svelte.
npx degit sveltejs/template my-svelte-project
cd my-svelte-project
Install Jest.
npm install --save-dev jest
or
yarn add --dev jest
After installation configure babel to support ES2015 modules
Add your test environment to .babelrc in the root of your project:
/// <reference types="babel" />
{
"env":{
"test":{
"plugins":["transform-es2015-modules-commonjs"]
}
}
}
npm install --save-dev babel-plugin-transform-es2015-modules-commonjs
And that's it. Jest will enable compilation from ES modules to CommonJS automatically, without having to inform additional options to your jest property inside package.json