jestjs - are there issues with generating a new wrapper for each test in Enzyme? -
i'm doing tests react project using jest + enzyme.
currently generate new wrapper each test in suite.
example:
it('should render title', () => { let wrapper = shallow(<component />); expect(wrapper.find('#title')).tohavelength(1); }); it('should call closemodal function when clicked', () => { let wrapper = shallow(<component />); wrapper.instance().closemodal = jest.fn(); let targetfunction = wrapper.instance().closemodal; expect(targetfunction).tohavebeencalled(); });
i know whether standard or should generating wrapper in beforeall , referencing one.
i'm interested in potential improvement in speed time. right have 190 tests , done in 21.38s.
the problem beforeall
use same instance in of test. if change internal state or props of component in 1 of test can influent result of other test.
normally use beforeall
test different parts of component without having generic test 'renders correct'
multiple small ones 'renders title'
, 'renders body'
, on, every test tests single part of component, make easier find place went wrong if test fails.
Comments
Post a Comment