All Projects β†’ janhesters β†’ riteway-jest

janhesters / riteway-jest

Licence: MIT license
Unit tests that always supply a good bug report when they fail for Jest.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to riteway-jest

awesome-javascript-testing
πŸ”§ Awesome JavaScript testing resources
Stars: ✭ 28 (+16.67%)
Mutual labels:  unit-testing, jest
Enzyme Matchers
Jasmine/Jest assertions for enzyme
Stars: ✭ 881 (+3570.83%)
Mutual labels:  unit-testing, jest
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:  unit-testing, jest
react-testing-talk
No description or website provided.
Stars: ✭ 12 (-50%)
Mutual labels:  unit-testing, jest
Snap Shot
Jest-like snapshot feature for the rest of us, works magically by finding the right caller function
Stars: ✭ 170 (+608.33%)
Mutual labels:  unit-testing, jest
tropic
🍍 Test Runner Library
Stars: ✭ 29 (+20.83%)
Mutual labels:  unit-testing, jest
Jasmine Matchers
Write Beautiful Specs with Custom Matchers for Jest and Jasmine
Stars: ✭ 552 (+2200%)
Mutual labels:  unit-testing, jest
Sazerac
Data-driven unit testing for Jasmine, Mocha, and Jest
Stars: ✭ 322 (+1241.67%)
Mutual labels:  unit-testing, jest
Lode
A universal GUI for unit testing
Stars: ✭ 51 (+112.5%)
Mutual labels:  unit-testing, jest
Express React Boilerplate
πŸš€πŸš€πŸš€ This is a tool that helps programmers create Express & React projects easily base on react-cool-starter.
Stars: ✭ 32 (+33.33%)
Mutual labels:  unit-testing, jest
testing-reactjs-examples
πŸ§ͺ "What should we test in our React components" - presentation examples.
Stars: ✭ 23 (-4.17%)
Mutual labels:  unit-testing, jest
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (+637.5%)
Mutual labels:  unit-testing, jest
angular-unit-testing-examples
Showroom for different Angular unit testing concepts
Stars: ✭ 19 (-20.83%)
Mutual labels:  unit-testing, jest
automock
A library for testing classes with auto mocking capabilities using jest-mock-extended
Stars: ✭ 26 (+8.33%)
Mutual labels:  unit-testing, jest
Enzyme To Json
Snapshot test your Enzyme wrappers
Stars: ✭ 954 (+3875%)
Mutual labels:  unit-testing, jest
Storybook Addon Jest
REPO/PACKAGE MOVED - React storybook addon that show component jest report
Stars: ✭ 177 (+637.5%)
Mutual labels:  unit-testing, jest
Sinon Jest Cheatsheet
Some examples on how to achieve the same goal with either of both libraries: sinon and jest. Also some of those goals achievable only by one of these tools.
Stars: ✭ 226 (+841.67%)
Mutual labels:  unit-testing, jest
jest-playground
Playing around with Jest - Subscribe to my YouTube channel: https://bit.ly/CognitiveSurge
Stars: ✭ 24 (+0%)
Mutual labels:  jest
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging πŸ€—
Stars: ✭ 20 (-16.67%)
Mutual labels:  unit-testing
fly-helper
It's a Tool library, method collection
Stars: ✭ 21 (-12.5%)
Mutual labels:  jest

RITEway-Jest

Inspired by Eric Elliott's RITEway.

Why?

TLDR: I wanted RITEway's assert for Jest.

I love RITEway's API because it forces you to write good unit tests by it's given-should API and only exposing the equals assertion.

Only problem is RITEway is build using tape. You can't use it with Jest, which in turn has some advantages and disadvantages.

Disadvantages

Advantages

You might want to check out RITEway because you can learn these advantages first hand. I prefer RITEway for React apps and use RITEway-Jest for React Native apps.

Installation

npm i --save-dev riteway-jest

or

yarn add --dev riteway-jest

Setup

React with CRA

Add an import in your src/setupTests.js.

import 'riteway-jest/src/riteway-jest.js';

React Native

Add to your jest key in package.json.

"jest": {
  "preset": "react-native",
  "setupFilesAfterEnv": ["node_modules/riteway-jest/src/riteway-jest.js"]
}

React Native with Expo

Add to your jest key in package.json.

"jest": {
  "preset": "jest-expo",
  "setupFilesAfterEnv": ["node_modules/riteway-jest/src/riteway-jest.js"]
}

jest.config.js instead of package.json.

module.exports = {
  setupFilesAfterEnv: [
    'node_modules/riteway-jest/src/riteway-jest.js',
    // ... other setup files ...
  ],
  // ... other options ...
};

Tips

ESLint complains

Add a global key to your .eslintrc.json.

{
  "_comment": "<Your other settings here>",
  "globals": {
    "assert": 'readonly'
  },
  "rules": {
    "_comment": "<Your rules here>"
  }
}

Usage

With pure functions.

const sum = (a = 0, b = 0) => a + b;

describe('sum()', () => {
  const should = 'return the correct sum';

  assert({
    given: 'no arguments',
    should: 'return 0',
    actual: sum(),
    expected: 0,
  });

  assert({
    given: 'zero',
    should,
    actual: sum(2, 0),
    expected: 2,
  });

  assert({
    given: 'negative numbers',
    should,
    actual: sum(1, -4),
    expected: -3,
  });
});

Using React Native Testing Library.

import React from 'react';
import { Text } from 'react-native';
import { render } from 'react-native-testing-library';

function MyText({ title }) {
  return <Text>{title}</Text>;
}

describe('Text component', () => {
  const createText = (props = {}) => render(<MyText {...props} />);

  {
    const props = { title: 'Foo' };
    const $ = createText(props).getByType;

    assert({
      given: 'a title',
      should: 'display the title',
      actual: $('Text').props.children,
      expected: props.title,
    });
  }
});

Using React Testing Library.

import PropTypes from 'prop-types';
import React from 'react';
import { cleanup, render } from 'react-testing-library';

function Button({ disabled, onClick, text }) {
  return (
    <button data-testid="foo" disabled={disabled} onClick={onClick}>
      {text}
    </button>
  );
}

Button.propTypes = {
  disabled: PropTypes.bool.isRequired,
  onClick: PropTypes.func.isRequired,
  text: PropTypes.string,
};

Button.defaultProps = {
  disabled: false,
  text: '',
};

describe('button component', () => {
  const createButton = (props = {}) =>
    render(<Button onClick={() => {}} {...props} />);

  {
    const props = { text: 'foo' };
    const $ = createButton(props).getByTestId;

    assert({
      given: 'a text',
      should: "render 'foo'",
      actual: $('foo').textContent,
      expected: props.text,
    });
    cleanup();
  }

  {
    const props = { disabled: true, text: 'foo' };
    const $ = createButton(props).getByText;

    assert({
      given: 'disabled',
      should: 'be disabled',
      actual: $('foo').hasAttribute('disabled'),
      expected: props.disabled,
    });
    cleanup();
  }
});

skip & only & todo

assert supports Jest's skip, only and todo functions.

// This test is explicitly skipped
assert.skip({
  given: 'something',
  should: 'be equal to something',
  actual: 'nothing',
  expected: 'something',
});

// This test gets executed
assert.only({
  given: 'something',
  should: 'be equal to something',
  actual: 'nothing',
  expected: 'something',
});

// This test is implicitly skipped because the .only() above
assert({
  given: 'something',
  should: 'be equal to something',
  actual: 'nothing',
  expected: 'something',
});

each is currently not supported.

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