1.0.0 • Published 8 years ago
jest-its v1.0.0
jest-its
Adds subject and its implementations from RSpec to Jest. jest-its is part of a suite of jest-addons in the package: jest-addons.
Getting Started
Install jest-its using yarn:
yarn add --dev jest-itsMotivation
Usage
If you want, you can import its and subject for each test file via:
import {its, subject} from 'jest-its';If you want to install its and subject as globals, you can modify the jest section of your package.json to include:
"jest": {
"setupFiles": [
"jest-its/setup"
]
},Example
Here's an example that tests the implementation of its:
import {its, subject} from '../';
describe('its', () => {
describe('with primitives', () => {
subject(() => ({a: 1, b: 2}));
its('a', () => isExpected.toEqual(1));
its('b', () => isExpected.toEqual(2));
});
describe('with functions', () => {
subject(() => ({a: () => 1, b: () => 2}));
its('a', () => isExpected.toEqual(1));
its('b', () => isExpected.toEqual(2));
});
describe('with nested properties', () => {
subject(() => ({a: {b: {c: 1, d: 2}}}));
its('a.b.c', () => isExpected.toEqual(1));
its('a.b.d', () => isExpected.toEqual(2));
});
});1.0.0
8 years ago