Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including jest-plugin-its with all npm packages installed. Try it out:

require("jest/package.json"); // jest is a peer dependency. var jestPluginIts = require("jest-plugin-its")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

jest-plugin-its v2.9.0

'subject' and 'its' implementations from RSpec in Jest.

jest-plugin-its

npm npm npm

Adds subject and its implementations from RSpec to Jest.

Getting Started

Install jest-plugin-its using yarn:

yarn add --dev jest-plugin-its

Motivation

Usage

If you want, you can import its and subject for each test file via:

import {its, subject} from 'jest-plugin-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-plugin-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));
  });
});
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free