我对 MobX 注入装饰器的理解是,使用 Enzyme,我应该能够在我的单元测试中简单地初始化一个存储,然后作为道具传递给我正在安装的组件。[src: https://semaphoreci.com/community/tutorials/how-to-test-react-and-mobx-with-jest并滚动到集成测试部分。] 但是我不断收到商店不可用!错误。这往往是一个问题,特别是如果我要注入多个商店。
所以在我的组件中:
export default inject('errorStore', 'someOtherStore', 'andTheThirdStore')(observer(MyComponent));
我的测试应该是这样的。
import errorStore from './stores/errorStore';
import someOtherStore from './stores/someOtherStore';
import andTheThirdStore from './stores/andTheThirdStore';
import Component from './components/Component';
describe('My Component', () => {
someOtherStore.initializeWithData('./examples','TEST-123-45678-90', 'USERID');
andTheThirdStore.initialize();
const storeProp = { errorStore, someOtherStore, andTheThirdStore };
beforeEach(() => {
const wrapper = mount(<Component {...storeProp} />
}
it ('does all the things', () => {...});
我在这里需要其他类型的提供者还是我只是错过了一些明显的东西?