If you're using Mocha or Jasmine to run tests against Svelte components, you'll need to configure Node to compile your .svelte
files. That's what this script does. It registers Svelte compilation outside of the production Rollup build process.
It also installs source map support so that stack traces map back to the original .svelte
file.
npm install --save-dev svelte-test-register
In package.json
, update the Mocha script entry to require svelte-test-register
:
"scripts": {
"mocha": "mocha --require svelte-test-register"
}
In spec/support/jasmine.json
, update the helpers section to include the index.js
from the svelt-test-register
package:
"helpers": [
"../node_modules/svelte-test-register/index.js"
]
Jest has a different mechanism for transforming specific files. See jest-transform-svelte if you'd like to test Svelte components in Jest.
Source map support does not yet work in Jasmine.
All contributions are welcome. Please feel free to create issues or raise PRs.