Jest snapshot error - PrettyFormatPluginError: wrapper.find is not a functionTypeError

Viewed 575

I was wondering if someone could help me with my Jest snapshot test not working.

Here is my code:

import React from 'react';
import { shallow } from 'enzyme';
import ProjectContainer from '../../../components/ProjectContainer/index';
import Image1 from '../../assets/image1.png';
import Image2 from '../../assets/image2.png';
import Key from '../../assets/personalkey.svg';
import Encryption from '../../assets/encryption.svg';
import TwoFactor from '../../assets/two-factor.svg';
import NativeSoftware from '../../assets/nativesoftware.svg';

const data = {
    titleText: 'Title Text',
    bodyText:
      'Body Texxt',
  };
  
  const images = {
      image1: Image1,
      image2: Image2,
  }
  
  const cardArray = [
    {
      image: Key,
      header: 'Key',
      body: 'Key Body',
    },
    {
      image: Encryption,
      header: 'Encryption',
      body: 'Encryption body',
    },
    {
      image: NativeSoftware,
      header: 'Native Software',
      body: `Native Software body`,
    },
    {
      image: TwoFactor,
      header: 'Two-factor',
      body: 'Two factor body',
    },
  ];

it('renders correctly', () => {
  const wrapper = shallow(<ProjectContainer data={data} images={images} cardArray={cardArray}/>);
  expect(wrapper).toMatchSnapshot();
});

The error message that I get is this:

 PrettyFormatPluginError: wrapper.find is not a functionTypeError: wrapper.find is not a function

Any help on this would be greatly appreciated! I've passed in all the correct props, yet still receive this issue. Previously, I've just deleted and recreated the file for a different snapshot test and that fixed the issue, but this time it does not work.

1 Answers

Shouldn't it be as following instead?

expect(wrapper.find(ProjectContainer)).toMatchSnapshot();

At least, as far as I get, you should use wrapper with one of its function.

Related