我正在尝试使用角操场,在那里我可以使用通用的模拟数据和单元测试用例,但是我无法执行以下操作
你能给我提个建议吗?
发布于 2020-06-21 17:14:49
在为依赖ngrx存储的组件制作沙箱时,我通常会这样做:
import { provideMockStore } from '@ngrx/store/testing';
const initialState = {
// put here what the state should look like for this sandbox
}
const sandboxConfig = {
imports: [
// module imports for the sandbox
],
declarations: [TheSandboxedComponent],
exports: [TheSandboxedComponent],
label: 'Component with ngrx mock store',
};
export default sandboxOf(TheSandboxedComponent, sandboxConfig)
.add('Default', {
// The template for the sandbox, adjust to your component
template: '<my-component></my-component>',
styles: [],
providers: [
// !!! Provide the mock ngrx store here, using the initialState
// defined above
provideMockStore({ initialState: initialState }),
],
})关键是使用ngrx provideMockStore().。请查看https://ngrx.io/guide/store/testing#using-a-mock-store和MockStore类文档,了解更多您可以做的事情,如模拟选择器、操作等.
https://stackoverflow.com/questions/60659740
复制相似问题