Neurophysiologically Pseudoscientific Manatee
    Wondering what’s next for npm?Check out our public roadmap! »

    mocha-chai-jest-snapshot
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.2 • Public • Published

    🍵mocha-chai-jest-snapshot📷

    Travis (.org) npm MIT

    NPM

    provides snapshot testing like jest

    Features

    • Simple to use
    • Output the same snapshot file as jest
    • Output the same snapshot summary as jest
    • Detect obsolete snapshots
    • Support custom serializer
    • Support typescript

    Usage

    npm i -D mocha-chai-jest-snapshot

    then add it to the test setup:

    // e.g. setup.js (mocha --file setup.js)
    const chai = require("chai");
    const { jestSnapshotPlugin } = require("mocha-chai-jest-snapshot");
    
    chai.use(jestSnapshotPlugin());

    enjoy.

    const { expect } = require("chai");
    it("foo", function () {
      expect({ foo: "bar" }).toMatchSnapshot();
    });
    > chai-snapshot@1.0.0 test /mnt/x/chai-snapshot
    > npx mocha --file setup.js -r ts-node/register test/**/*.ts
    
    
      ✓ foo
    
    Snapshot Summary
     › 1 snapshot written from 1 test suite.
    
      1 passing (9ms)
    
    // Jest Snapshot v1, https://goo.gl/fbAQLP
    
    exports[`foo 1`] = `
    Object {
      "foo": "bar",
    }
    `;

    update snapshots

    # set envoriment
    UPDATE_SNAPSHOT=1 mocha ...
    # or add command line argument
    mocha ... --update

    report at the end

    npx mocha ... --reporter mocha-chai-jest-snapshot/reporters/spec

    with options

    jest options (setup)

    const chai = require("chai");
    const { jestSnapshotPlugin } = require("mocha-chai-jest-snapshot");
    
    chai.use(
      jestSnapshotPlugin({
        rootDir: "../",
        snapshotResolver: "<rootDir>/jest/snapshotResolver",
        snapshotSerializers: ["jest-serializer-vue"],
      })
    );

    jest options (package.json)

    {
      "jest": {
        "rootDir": "../",
        "snapshotResolver": "<rootDir>/jest/snapshotResolver",
        "snapshotSerializers": ["jest-serializer-vue"]
      }
    }

    jest options (jest.config.js)

    module.exports = {
      rootDir: "../",
      snapshotResolver: "<rootDir>/jest/snapshotResolver",
      snapshotSerializers: ["jest-serializer-vue"],
    };

    custom serializer

    const chai = require("chai");
    const {
      jestSnapshotPlugin,
      addSerializer,
    } = require("mocha-chai-jest-snapshot");
    const customSerializer = require("...");
    
    chai.use(jestSnapshotPlugin());
    addSerializer(customSerializer);

    or

    const { expect } = require("chai");
    const customSerializer = require("...");
    
    expect.addSnapshotSerializer(customSerializer);

    Install

    npm i mocha-chai-jest-snapshot

    DownloadsWeekly Downloads

    2,069

    Version

    1.1.2

    License

    MIT

    Unpacked Size

    52.9 kB

    Total Files

    86

    Last publish

    Collaborators

    • avatar