LuJ*_*aks 4 unit-testing karma-runner redux ionic2 angular
我正在尝试使用基于 angular2-redux 的 Ionic2 rc1(使用 angular 2.0.0)应用程序实现业力单元测试的可能性。karma 设置基本上是从以下 repo 中采用的:https : //github.com/lathonez/clicker并且工作正常。我有一个简单的计数器 redux 实现也可以正常工作。当我尝试为我的测试设置 angular2-redux 时,出现以下错误:
未捕获的 ReferenceError:进程未定义在 webpack:///Users/luki/Applications/ionic/ionic2-redux-example/~/redux/es/index.js:14:0 <- src/test.ts:65041
我知道进程未在浏览器中定义,但仅可用于服务器上的节点。我需要如何调整我的 karma 配置才能使用 angular2-redux ?
调用 createAppStoreFactory 函数以在 TestBed.configureTestingModule 中提供我的 AppStore 会导致此错误。
我的测试设置可以在以下 repo 中找到:https : //github.com/lujakob/ionic2-redux-example/blob/master/src/test.ts
任何帮助表示赞赏!
(npm angular2-redux 有一个演示应用程序和一个示例测试设置。但这依赖于
即使这几乎是一个三年前的问题,对于面临这个问题的其他人,这是我的解决方案:
由于process仅在 NodeJS 中定义而不在浏览器中定义,我们必须告诉 karma 它应该“伪造”它。
创建一个 javascript 文件并根据需要为其命名(例如global-variables.js),内容如下:
const process = {
env: {
NODE_ENV :'production'
}
};
Run Code Online (Sandbox Code Playgroud)
在您的 中karma.conf.js,将此文件作为数组中的第一个导入导入files[]:
(...)
files: [
'./test/global-variables.js',
{ pattern: config.grep ? config.grep : 'test/**/*.test.ts', type: 'module' }
],
(...)
Run Code Online (Sandbox Code Playgroud)
那应该至少修复ReferenceError: process is not defined.
| 归档时间: |
|
| 查看次数: |
1003 次 |
| 最近记录: |