Enzyme shallow rendersについての議論があり、各試験で浅く再試験するための1回の試験時間があります。メソッド、クリック、セレクタの長さなどであれば、コンポーネントを1回レンダリングすると、テストがより速く実行されることが示唆されています。の前に、のテストが実行され、の各時間がになります。酵素/反応浅いレンダリングは高価ですか?
いずれの方法でも、どちらの方法がより速く、どちらの場合でも落とし穴があると指摘できる専門家はいますか?これらの例ではランナーAVAを使用しています(やはり議論のために少し工夫しました)。
は、例えば、ここに...
import TagBox from '../TagBox';
const props = { toggleValue: sinon.spy() };
let wrapper = {};
test.before(t => {
wrapper = shallow(<TagBox />);
});
test('it should have two children', t => {
t.is(wrapper.children().length, 2);
});
test('it should safely set props', t => {
wrapper.setProps({...props});
t.is(wrapper.children().length, 2);
});
test('it should call when clicked', t => {
wrapper.setProps({...props});
wrapper.find({tagX : true}).last().simulate('click');
t.true(props.toggleValue.calledOnce);
});
を片道()ですそして、ここで他の(B)だ...
import TagBox from '../TagBox';
test('it sets value to null ...', t => {
const props = {multiple: false};
const wrapper = shallow(<TagBox {...props} />);
t.is(wrapper.state('currentValue'), null);
});
test('it sets value to [] if multiple', t => {
const props = {multiple: true};
const wrapper = shallow(<TagBox {...props} />);
t.deepEqual(wrapper.state('currentValue'), []);
});
test('it does not use value if ...', t => {
const props = = {value: 3};
const wrapper = shallow(<TagBox {...props} />);
t.is(wrapper.state('currentValue'), null);
});
// etc. etc.
お知らせテストBでいます、本質的に何も変更されていないが、小道具の場合には、各テストのための新しい浅いラッパーがあります。
100回のテストで、完成までの時間の差はどうなると思いますか?
また、高いスコープの一度(テストA)はテスト状態を汚染する可能性がありますか?