score:-1

it("should render right", () => { 
  const component = shallow(<testuser />);
  const element = component.find('wrapper');
  chai.expect(element.props.children).to.have.length(3); 
});

score:-1

use ().toequal() instead of .to.have.length() as .to.have is not any function in jest expect library visit here for more info

import react from "react";
import testuser from "./testuser";
import { shallow } from "enzyme";

it("should render right", () => {
const component = shallow(<testuser />);

expect(component.find('card').length).toequal(3);
});

score:1

try this out. you have to give it as a string literal. also to me the expect library you are using is not the one you get from chai and may have different set of helper methods, hence giving that error. unfortunately i don't have the code with me to check further. nothing wrong with shallow rendering at all.

import react from "react";
import testuser from "./testuser";
import { shallow } from "enzyme";
import { expect } from 'chai';

it("should render right", () => {
  const component = shallow(<testuser />);
  expect(component.find('card')).to.have.length(3);
});

also you don't need to have this statement here, import card from "./card";

in the testuser component change the import statement like this.

import card from "./card";

so now your testuser component should look like this.

import react from "react";
import card from "./card";

const testuser = () => {
  return (
    <div>
      <div classname="test" />
      <div classname="wrapper">
        <card />
        <card />
        <card />
      </div>
    </div>
  );
};

export default testuser;

use the following command to install chai library.

npm install --save chai

if you really want to use jest change your assertion as below.

import react from "react";
import testuser from "./testuser";
import { shallow } from "enzyme";

it("should render right", () => {
  const component = shallow(<testuser />);
  expect(component.find('card')).tohavelength(3);
});

personally i like mocha due to it's fluent api.

hope this helps. happy coding !

score:1

shallow rendering won't go as deep as you want in this case because of your div nesting. http://airbnb.io/enzyme/docs/api/shallow.html

either use mount or use .dive() api to go one level further. see the example in the enzyme docs: http://airbnb.io/enzyme/docs/api/shallowwrapper/dive.html

score:2

i have the same problem. it solved by using the below .

i have created a jest.config.js file at the root level and add below code.

module.export ={
  setupfiles:[ '<rootdir>/src/setuptests.js']
 }

i have created setuptests.js file and add below code.

import { configure } from 'enzyme';
import adapter from 'enzyme-adapter-react-16';

configure({ adapter: new adapter() });

and solved my problem.


Related Query

More Query from same tag