jeudi 17 janvier 2019

What is the difference between shallow & render in jest?

In jest, what is the difference between using shallow & render?

Here is an example of both:

Test rendering with shallow:

import "jest";
import * as React from "react";
import { shallow } from "enzyme";
import Item from "../item.component";

describe("Item", () => {
  it("renders correct", () => {
    const item = {
        name: "A"
      };

    const component = shallow(
      <Item item={item}/>
    );

    expect(component).toMatchSnapshot();
  });
});

Test rendering with render

import "jest";
import * as React from "react";
import { render } from "enzyme";
import Item from "../item.component";

describe("Item", () => {
  it("renders correct", () => {
    const item = {
        name: "A"
      };

    const component = render(
      <Item item={item}/>
    );

    expect(component).toMatchSnapshot();
  });
});

What are the typical usage of these 2. I wrote all my tests with shallow, should I go back and change that to render in some cases?

Aucun commentaire:

Enregistrer un commentaire