我們正在進行關於酶shallow renders的工作討論,以及每次測試重新運行淺試驗的時間。無論是方法,點擊,選擇器長度等,我建議我們的測試可能運行得更快,如果我們淺顯示組件一次之前測試運行與每個時間。酶/反應淺呈現昂貴?
有沒有專家能指出哪種方式更快,哪種方式有缺陷?這些例子正在使用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);
});
而這裏的其他(乙)...
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)在更高的範圍會污染測試狀態?