mardi 5 février 2019

Jest Enzyme testing

I have this Component:

export const MyComponent= ({ children, style }: Props) => (
  <p className="component-class-name" style={style}>
    {children}
  </p>
);

and I'm trying to test it, so I think there was two cases in the test, one with children, and second is without. Here is my 'with children' test snippet:

  it("should render properly with children", () => {
    const children = <span>MyComponent children</span>;
    const wrapper = mount(<MyComponent {...props}>{children}</MyComponent>);
    expect(wrapper.find(".component-class-name").exists()).toBe(true);
    expect(wrapper.find("span")).toHaveLength(1);
  });

but I think there is better way to test children. Is it okay or I'm doing something wrong? For testing I use Jest and Enzyme.

Aucun commentaire:

Enregistrer un commentaire