@magic/test
@magic/test
Declaratively test your ecmascript module files. No transpiling of either your codebase nor the tests. Incredibly fast.
Getting Started
See the Getting Started guide for full instructions.
npm i --save-dev --save-exact @magic/test// test/yourFileToTest.jsexport default [{ fn: () => true, expect: true, info: 'true is true' },]
Features
- Write tests in plain JavaScript or TypeScript
- Utility functions for deep equality, mocking, HTTP, and more
- Svelte 5 component testing built-in
- CLI tools with sharding for parallel test execution
- Test isolation for preventing state leakage
- Error codes for programmatic error handling
Quick Examples
Simple test
export default [{ fn: () => 1 + 1, expect: 2 },{ fn: () => 'hello', expect: 'hello']
Async test
import { promise } from '@magic/test'export default [{fn: promise(cb => setTimeout(() => cb(null, true), 100)),expect: true,info: 'handle promises',},]
Deep equality
import { is } from '@magic/test'export default [{fn: () => ({ a: 1, b: 2 }),expect: is.deep.equal({ a: 1, b: 2 }),info: 'deep compare objects',},]
Mock function
import { mock } from '@magic/test'export default [{fn: () => {const spy = mock.fn()spy('arg1')return spy.calls.length === 1},expect: true,info: 'mock tracks calls',},]
Learn More
- Getting Started - install, setup, first test
- Writing Tests - hooks, promises, types, multiple tests
- Utility Functions - deep, fs, curry, log, vals, env, http, mock, has
- Svelte Testing - mount components, interact, assert
- Svelte 4 vs 5 - feature comparison
- Svelte Auto-Export FAQ - $state and $derived exports
- CLI & Usage - flags, sharding, performance tips
- CLI Flags Reference - detailed flag table
- CLI Sharding Cheat-Sheet - CI/CD examples
- Performance Tips - optimization techniques
- Common Pitfalls - troubleshooting tips
- Test Isolation - prevent state leakage between tests
- Error Codes - programmatic error handling
- Error Codes Quick Look - quick reference table
- - detailed release history
This library tests itself. Have a look at the tests on GitHub.