mardi 6 novembre 2018

React - How to test a decorated class

how can I test a decorated component? I decorated a component using the react-tracking library, like:

@track((props) => ({category: 'EDIT', page: 
props.history.location.pathname}))
class EditTemplate extends React.Component<Props, State> {...}

export default EditTemplate;

When I try to test it like this:

it("test description", () => {
    const wrapper = mount(<EditTemplate history={mockHistory}/>);
    expect(wrapper.prop("history")).toEqual("xyz");
    expect(wrapper.state("code")).toEqual("some value");
});

the prosp test works fine, but the state is always null! I tried using instance(), dive(), get(0), with the wrapper but the result it's always the same. If I remove the decorator, the test passes. Any suggestions? Thanks

Aucun commentaire:

Enregistrer un commentaire