@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

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

This library tests itself. Have a look at the tests on GitHub.