jest-preset-ns

An opinionated Jest preset for both react and non-react projects

Usage no npm install needed!

<script type="module">
  import jestPresetNs from 'https://cdn.skypack.dev/jest-preset-ns';
</script>

README

jest-preset-ns

npm version Build Status

An opinionated Jest preset for both react and non-react projects.

It comes with two default presets with both babel and typescript support.

Features

  • default preset and preset for react are available
  • modern javascript (babel) and typescript (ts-jest) support
  • mocks files (eg. png, gif, jpg, ...) and date (jest-date-mock) automatically
  • looks for tests in __tests__ and for *.(spec|test).[jt]s(x)? files
  • easy extendable

Installation

npm install --save-dev jest-preset-ns jest
# or
yarn add jest-preset-ns jest --dev

Usage

Add jest-preset-ns as preset to your Jest config. This can be done by adding it to your package.json or jest.config.js:

// package.json
{
  "jest": {
    "preset": "jest-preset-ns"
  }
}
// jest.config.js
module.exports = {
  preset: 'jest-preset-ns',
  // or: preset: 'jest-preset-ns/presets/default'
  // [...]
}

Feel free to extend the "jest"-configuration object along the way with your own settings.

For running tests, use the Jest CLI.

Compatibility

This package is compatible only with React 16+.

Helpful tips

How to Publish

# create the tags and the version
yarn lerna:version

# create the changelog entry
npx lerna-changelog --from <tag> --to <tag>
git add CHANGELOG.md && git commit -m "chore: updated CHANGELOG"

# push the tags and the changelog update
git push --follow-tags

# publish to npm
yarn lerna:publish

References