我用
beforeEach
就像在我的react组件测试中一样。
let component;
let configProp;
beforeEach(() => {
component = shallow(<MyComponent config={configProp} />);
});
现在,我想改变
configProp
测试中的变量。像这样的:
let component;
let configProp;
beforeEach(() => {
component = shallow(<MyComponent config={configProp} />);
});
// runs before beforeEach for the next test
beforeNext(() => {
const config_1 = {...};
configProp = config_1;
});
test('config_1', () => {
// component now has config=config_1
expect(component.find({config: config_1}).exists());
});
有可能吗?或者,我们必须
shallow(<MyComponent />)
每次单独测试?
现在,我正在使用
it
块为下一个函数更改配置。这是合法的吗?像这样的:
it('changes configProp', () => {
const config_1 = {...};
configProp = config_1;
});
test('config_1', () => {
expect(component.find({config: config_1}).exists());
});