If you look at test 2 and 3, which one would be the correct way to setup and test what we expect ?
Is there any performance issue, memory leak or "bad way of doing things" that should be looked at here ?
import { shallow } from 'enzyme';
import Component from 'path/to/my/component';
describe('<Component />', () => {
const defaultProps = {...};
const setup = (props = {}) => shallow(<Component {...defaultProps, ...props} />);
let wrapper;
describe('tests ...', () => {
beforeEach(() => { wrapper = setup(); });
// 1 - Use the wrapper without additional props
it('should ...', () => {
expect(wrapper.find('selector')).toHaveLength(1);
});
// 2 - Use setup with additional props directly inside an expect
it('should ...', () => {
expect(setup({ bar: 'bar' }).find('selector')).toHaveLength(0);
});
// 3 - Override wrapper with additional props and use it inside an expect
it('should ...', () => {
wrapper = setup({ bar: 'bar' });
expect(wrapper.find('selector')).toHaveLength(0);
});
});
});
Aucun commentaire:
Enregistrer un commentaire