Jest: expect(...).toMatchSnapshot is not a function

Created on 11 Aug 2016  路  4Comments  路  Source: facebook/jest

Using Jest CLI v11.0.2, jasmine2, babel-jest

screen shot 2016-08-11 at 10 42 53

Most helpful comment

To be able to use snapshot testing you need to update Jest to 14 (you are using 11 atm)

All 4 comments

To be able to use snapshot testing you need to update Jest to 14 (you are using 11 atm)

Yep, thank you

I have this issue with jest 24.1.0 and yarn 1.13.0.
My test

import React from 'react';
import Adapter from 'enzyme-adapter-react-16';
import { shallow, configure } from 'enzyme';
import DocLink from '../doc_link';

configure({adapter: new Adapter()});
describe('DocLink', () => {
  it('renders correctly', () => {
    const url = 'https://bunkat.github.io/later/parsers.html#text';
    const text = 'Schedule syntax';
    const docLink = shallow(<DocLink url={url} text={text} />);
    expect(docLink).toMatchSnapshot();
  });
});

I tried to import expect but got the same error

import expect from 'expect';

and

const expect = require('expect');

@sergibondarenko expect doesn't have .toMatchSnapshot custom matcher installed by default, they're injected through test environment (see jestExpect.js files in Jest source). Use global expect and it will work.

Was this page helpful?
0 / 5 - 0 ratings