svelte-jest

Svelte Jest

set up the jest environment in a svelte project without a configuration

Svelte-jest

Unit testing Svelte projet in Jest

Install

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

Configuration

After installation configure babel to support ES2015 modules

Step 1 :

Add your test environment to .babelrc in the root of your project:

/// <reference types="babel" />
{
    "env":{
        "test":{
            "plugins":["transform-es2015-modules-commonjs"]
        }
    }
}

Step 2 :

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

Top categories

Loading Svelte Themes