3

尝试使用现有和最近迁移的 Angular 7 项目运行简单的效果测试。但我得到如下错误。

错误: 在 getTestScheduler (node_modules/jasmine-marbles/es6/src/scheduler.js:11:1) 在新的 TestHotObservable (node_modules/jasmine-marbles/es6/src/test-observables.js:21:39)没有初始化测试调度程序) 在 Module.hot (node_modules/jasmine-marbles/es6/index.js:7:1)

我在效果规范文件中的代码是使用 jasmine-marbles 进行的基本标准检查。

const action = new Load(request);
const completion = new LoadSuccess(result);

actions$ = hot('-a-', { a: action});
const response = cold('-a|', {a: result});
const expected = cold('--b', {b: completion});
service.getSomething.and.returnValue(result);
expect(effects.load$).toBeObservable(expected);

以前有没有人看到并解决过这个错误?

4

4 回答 4

9

虽然改用 ES5 解决了这个问题,但我的同事提出了一个更好的解决方案。解决方案是在 src/test.ts 文件中添加以下行。我更喜欢它,因为它允许在 ES6 中继续测试。

import { addMatchers, getTestScheduler, initTestScheduler, resetTestScheduler } from 'jasmine-marbles';

// configure matchers for jasmine-marbles
jasmine.getEnv().beforeAll(() => {
  return addMatchers();
});
jasmine.getEnv().beforeEach(() => {
 initTestScheduler();
});
jasmine.getEnv().afterEach(() => {
 getTestScheduler().flush();
 resetTestScheduler();
});
于 2019-03-21T12:53:12.603 回答
7

将 jasmine-marbles 升级到 0.6.0 为我解决了这个问题。

于 2019-06-19T10:28:51.133 回答
0

经过进一步研究发现这是由于 tsconfig.spec.json 中的编译器选项造成的。最初它被设置为“target”:“es6”,将其更改为 es5 修复了这个问题,并且规范现在可以成功运行。

于 2019-03-18T15:07:13.107 回答
0

No test scheduler initialized在我的情况下,错误的原因是在块cold外使用。beforeEach

在块内创建测试 observablesbeforeEach解决了这个问题。

于 2021-08-24T19:08:06.227 回答