All Projects → algolia → Expect Jsx

algolia / Expect Jsx

Licence: mit
✅ toEqualJSX for expect assertion library

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Expect Jsx

Snap Shot
Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
Stars: ✭ 170 (-58.64%)
Mutual labels:  jest, jsx
Js Toolbox
CLI tool to simplify the development of JavaScript apps/libraries with little to no configuration. (WORK IN PROGRESS/PACKAGE NOT PUBLISHED).
Stars: ✭ 53 (-87.1%)
Mutual labels:  jest, jsx
Webpack React Boilerplate
Minimal React 16 and Webpack 4 boilerplate with babel 7, using the new webpack-dev-server, react-hot-loader, CSS-Modules
Stars: ✭ 358 (-12.9%)
Mutual labels:  jest
Jest Runner Eslint
An ESLint runner for Jest
Stars: ✭ 401 (-2.43%)
Mutual labels:  jest
Js Stack From Scratch
🛠️⚡ Step-by-step tutorial to build a modern JavaScript stack.
Stars: ✭ 18,814 (+4477.62%)
Mutual labels:  jest
Shop
🛍🛒 Full-stack React/Prisma/TS/GraphQL E-Commerce Example
Stars: ✭ 359 (-12.65%)
Mutual labels:  jest
Gatsby Starter
Gatsby 2.0 starter with typescript and many cools dev tools
Stars: ✭ 385 (-6.33%)
Mutual labels:  jest
Pwa
An opinionated progressive web app boilerplate
Stars: ✭ 353 (-14.11%)
Mutual labels:  jest
Vidom
Library to build UI based on virtual DOM
Stars: ✭ 408 (-0.73%)
Mutual labels:  jsx
Typescript Library Starter
Starter kit with zero-config for building a library in TypeScript, featuring RollupJS, Jest, Prettier, TSLint, Semantic Release, and more!
Stars: ✭ 3,943 (+859.37%)
Mutual labels:  jest
Vue Tsx Support
TSX (JSX for TypeScript) support library for Vue
Stars: ✭ 397 (-3.41%)
Mutual labels:  jsx
Nx Examples
Example repo for nx workspace
Stars: ✭ 372 (-9.49%)
Mutual labels:  jest
Mercury Parser
📜 Extract meaningful content from the chaos of a web page
Stars: ✭ 4,025 (+879.32%)
Mutual labels:  jest
Gdlauncher
GDLauncher is a simple, yet powerful Minecraft custom launcher with a strong focus on the user experience
Stars: ✭ 386 (-6.08%)
Mutual labels:  jsx
Nod
Node.js module generator/boilerplate with Babel, Jest, Flow, Documentation and more
Stars: ✭ 355 (-13.63%)
Mutual labels:  jest
Jest Cheat Sheet
Jest cheat sheet
Stars: ✭ 4,309 (+948.42%)
Mutual labels:  jest
Emoji
⭕〽️❗Awesome Omi 创意坊 - 如果你愿意,我希望未来是你和Omi~
Stars: ✭ 355 (-13.63%)
Mutual labels:  jsx
Msx
JSX for Mithril.js 0.x
Stars: ✭ 370 (-9.98%)
Mutual labels:  jsx
Enzyme
JavaScript Testing utilities for React
Stars: ✭ 19,781 (+4712.9%)
Mutual labels:  jest
React Espanol
Recursos para aprender ReactJS en español
Stars: ✭ 409 (-0.49%)
Mutual labels:  jsx

Note from maintainers Since Jest supports snapshot testing, we recommend you to use that instead of expect-jsx.

expect-jsx is no more compatible with recent Jest versions (22), it can be made compatible so feel free to open a PR if so.

expect-jsx

Version Build Status License Downloads

toEqualJSX for mjackson/expect.

It uses algolia/react-element-to-jsx-string in the background to turn React elements into formatted strings.

Table of Contents generated with DocToc

Setup

You will most probably use this plugin as a development dependency.

yarn add expect-jsx --dev

API

  • expect(ReactComponent|JSX).toEqualJSX(ReactComponent|JSX)
  • expect(ReactComponent|JSX).toNotEqualJSX(ReactComponent|JSX)
  • expect(ReactComponent|JSX).toIncludeJSX(ReactComponent|JSX)
  • expect(ReactComponent|JSX).toNotIncludeJSX(ReactComponent|JSX)

Usage

Here's an example using mochajs/mocha.

import React from 'react';
import expect from 'expect';
import expectJSX from 'expect-jsx';

expect.extend(expectJSX);

class TestComponent extends React.Component {}

describe('expect-jsx', () => {
  it('works', () => {
    expect(<div />).toEqualJSX(<div />);
    // ok

    expect(<div a="1" b="2" />).toEqualJSX(<div />);
    // Error: Expected '<div\n  a="1"\n  b="2"\n/>' to equal '<div />'

    expect(<span />).toNotEqualJSX(<div/>);
    // ok

    expect(<div><TestComponent /></div>).toIncludeJSX(<TestComponent />);
    // ok
  });
});

It looks like this when ran:

Screenshot when using mocha

A note about functions

toEqualJSX will not check for function references, it only checks that if a function was expected somewhere, there's also a function in the actual data.

It's your responsibility to then unit test those functions.

Environment requirements

The environment you use to use react-element-to-jsx-string should have ES2015 support.

Use the Babel polyfill or any other method that will make you environment behave like an ES2015 environment.

Test

yarn test
yarn test:watch

Build

yarn build
yarn build:watch

Release

Decide if this is a patch, minor or major release, look at http://semver.org/

yarn release [major|minor|patch|x.x.x]

Similar projects

There are multiple similar projects for other assertions libraries, all based on algolia/react-element-to-jsx-string. For instance:

  • chai-equal-jsx, assertions for chai: expect(<div />).to.equalJSX(<div />);
  • chai-jsx, assertions for chai: expect(<div />).jsx.to.equal(<div />);
  • jsx-chai, assertions for chai: expect(<div />).to.deep.equal(<div />);
  • tape-jsx-equals, assertions for tape: t.jsxEquals(<div />, <div />);
  • jasmine-expect-jsx, assertions for jasmine: expect(<div />).toEqualJSX(<div />);

Thanks

To the people pointing me in the right directions like:

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].