All Projects → ruyadorno → Preact Jest Snapshot Test Boilerplate

ruyadorno / Preact Jest Snapshot Test Boilerplate

Licence: mit
🚀 Test Preact components using Jest snapshots

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Preact Jest Snapshot Test Boilerplate

React Modern Library Boilerplate
Boilerplate for publishing modern React modules with Rollup
Stars: ✭ 285 (+1087.5%)
Mutual labels:  boilerplate, preact
Pwa
An opinionated progressive web app boilerplate
Stars: ✭ 353 (+1370.83%)
Mutual labels:  boilerplate, jest
React Bolt
⚡ The most simple & robust boilerplate for your React projects.
Stars: ✭ 298 (+1141.67%)
Mutual labels:  boilerplate, jest
Simple React App
Simple base app using react, react-router v4, hot-reload & sass.
Stars: ✭ 263 (+995.83%)
Mutual labels:  boilerplate, jest
Laravel Vue Boilerplate
🐘 A Laravel 6 SPA boilerplate with a users CRUD using Vue.js 2.6, GraphQL, Bootstrap 4, TypeScript, Sass, and Pug.
Stars: ✭ 472 (+1866.67%)
Mutual labels:  boilerplate, jest
Rockpack
Rockpack is a simple solution for creating React Application with Server Side Rendering, bundling, linting, testing within 5 minutes
Stars: ✭ 265 (+1004.17%)
Mutual labels:  boilerplate, jest
Electron React Boilerplate
A Foundation for Scalable Cross-Platform Apps
Stars: ✭ 18,727 (+77929.17%)
Mutual labels:  boilerplate, jest
jest-serializer-html-string
A better Jest snapshot serializer for plain html strings
Stars: ✭ 17 (-29.17%)
Mutual labels:  serializer, snapshot
Graphql Dataloader Boilerplate
Very simple boilerplate using GraphQL and DataLoader
Stars: ✭ 405 (+1587.5%)
Mutual labels:  boilerplate, jest
Preact Starter
Webpack3 boilerplate for building SPA / PWA / offline front-end apps with Preact
Stars: ✭ 384 (+1500%)
Mutual labels:  boilerplate, preact
jest-preset-preact
Jest preset for testing Preact apps
Stars: ✭ 14 (-41.67%)
Mutual labels:  preact, jest
Express Babel
Express starter kit with ES2017+ support, testing, linting, and code coverage
Stars: ✭ 621 (+2487.5%)
Mutual labels:  boilerplate, jest
reducer-tester
Utilities for testing redux reducers
Stars: ✭ 19 (-20.83%)
Mutual labels:  jest, snapshot
React Native Navigation Redux Starter Kit
React Native Navigation(v2) Starter Kit with Redux, Saga, ESLint, Babel, Jest and Facebook SDK 😎
Stars: ✭ 271 (+1029.17%)
Mutual labels:  boilerplate, jest
patent-free-react-ecosystem-migration-plan
Patent Free React Ecosystem Migration Plan
Stars: ✭ 15 (-37.5%)
Mutual labels:  preact, jest
React Redux Boilerplate
Awesome React Redux Workflow Boilerplate with Webpack 4
Stars: ✭ 307 (+1179.17%)
Mutual labels:  boilerplate, jest
Arc
React starter kit based on Atomic Design
Stars: ✭ 2,780 (+11483.33%)
Mutual labels:  boilerplate, jest
Enzyme To Json
Snapshot test your Enzyme wrappers
Stars: ✭ 954 (+3875%)
Mutual labels:  serializer, jest
Nod
Node.js module generator/boilerplate with Babel, Jest, Flow, Documentation and more
Stars: ✭ 355 (+1379.17%)
Mutual labels:  boilerplate, jest
Snapshot Diff
Diffing snapshot utility for Jest
Stars: ✭ 490 (+1941.67%)
Mutual labels:  jest, snapshot

preact-jest-snapshot-test-boilerplate

Build Status license

A boilerplate for a very minimal setup running Jest snapshot tests on Preact components using preact-render-to-string rendering.

Requirements

The following are the very minimal requirements in order to use the Jest snapshot tests.

  • Jest
    • jest-serializer-html-string plugin dependency
    • extra config added on package.json file
  • Preact
    • preact-render-to-string
  • Babel
    • babel-plugin-transform-react-jsx

Example walkthrough

Component example

A very simple stateless functional component is defined on the ./thing.js file:

module.exports = ({ name, link }) => (
	<a href={ link }>{ name }</a>
);

Snapshot testing

The boilerplate on how to snapshot-test using Jest is available on ./__tests__/thing.js:

const render = require('preact-render-to-string');
const Thing = require('../thing');

describe('Thing component', () => {
	it('should render with a provided name', () => {
		const tree = render(
			<Thing name="Lorem Ipsum" />
		);
		expect(tree).toMatchSnapshot();
	});
});

Snapshots

Snapshot of expected rendering are stored on ./__tests__/__snapshots__/thing.js.snap:

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Thing component should render a thing containing a link 1`] = `<a href="https://mobile.twitter.com">Lorem Ipsum</a>`;

Running tests

If you need more info about Jest please visit their documentation. In order to run the tests from this example just run:

npm test

Updating snapshots

Keep in mind that when working with snapshots and modifying components, the snapshots needs to be updated in order for tests to pass. To do so just run:

npm test -- -u

License

MIT © Ruy Adorno

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].