jest-lite
Run Jest in the browser.
Why create this?
Codesandbox allows you to write Jest and execute the tests right in their environment. Getting this to work took a bit of research as Jest is typically meant to be ran in a Node environment. The Codesandbox team however didn't open-source their solution so I decided to write my own, for two reasons:
- Create an easy way to use Jest in any sandboxing environment.
- Give code sandbox maintainers a bare-bone example that shows how you can implement Jest testing into your own code sandboxing solution.
Modules
This library consists of three seperate modules which extend eachother's functionality:
core
All core testing utilities. (source)
- NPM:
import * as core from 'jest-lite';
- CDN:
http://unpkg.com/jest-lite@1.0.0-alpha.4/dist/core.js
enzyme
Testing utilities for testing with Enzyme. (source)
To be able to use this module you will need to include your preferred version of React and ReactDOM.
- NPM:
import * as enzyme from 'jest-lite/build/enzyme';
- CDN:
http://unpkg.com/jest-lite@1.0.0-alpha.4/dist/enzyme.js
prettify
The core
module spits out the test results in JSON format. This module gives you an easy way to prettify that output for use on a HTML page. (source)
- JS:
- NPM:
import * as prettify from 'jest-lite/build/prettify';
- CDN:
http://unpkg.com/jest-lite@1.0.0-alpha.4/dist/prettify.js
- NPM:
- Styles:
- NPM:
node_modules/jest-lite/dist/prettify.css
- CDN:
http://unpkg.com/jest-lite@1.0.0-alpha.4/dist/prettify.css
- NPM:
Examples
Basic Usage (NPM)
Check out this example on RunKit.
; describe'sum',; ;console.logresult;
Testing React and Prettifying Output (CDN)
Check out this example on Codepen.