首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用任何模拟框架在角操场模拟ngrx存储

无法使用任何模拟框架在角操场模拟ngrx存储
EN

Stack Overflow用户
提问于 2020-03-12 18:11:13
回答 1查看 200关注 0票数 0

我正在尝试使用角操场,在那里我可以使用通用的模拟数据和单元测试用例,但是我无法执行以下操作

  • Mock NgRx存储在角游乐场沙箱场景中,使用TS-mockito
  • 无法为单元测试(Karma)和角操场创建通用的模拟数据。有可能吗?

你能给我提个建议吗?

EN

回答 1

Stack Overflow用户

发布于 2020-06-21 17:14:49

在为依赖ngrx存储的组件制作沙箱时,我通常会这样做:

代码语言:javascript
复制
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类文档,了解更多您可以做的事情,如模拟选择器、操作等.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60659740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档