rxjs - 无法运行最简单的 rxjs-marbles 测试
问题描述
在全新安装ng new myapp
(cli 版本 1.6.8、Angular 5.2.0、rxjs 5.5.6)时,我安装了 rxjs 弹珠。
由于某些配置原因,我在运行非常基本的测试时遇到问题。谁能告诉我出了什么问题?
import { TestBed, async } from '@angular/core/testing';
import { marbles } from 'rxjs-marbles/jasmine';
import { map } from 'rxjs/operators';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent,
],
}).compileComponents();
}));
it('should see mapped values', marbles(m => {
const values = { a: 1, b: 2, c: 3, x: 2, y: 4, z: 6 };
const source = m.cold('--a---b---c-|', values);
const expected = m.cold('--x---y---z-|', values);
const result = source.pipe(map(x => x * 2));
m.expect(result).toBeObservable(expected);
}));
});
控制台错误:
ERROR in ./node_modules/rxjs-marbles/esm5/marbles.js
Module not found: Error: Can't resolve 'rxjs/testing' in '/Users/armo/Code/rxjsmarbles/node_modules/rxjs-marbles/esm5'
@ ./node_modules/rxjs-marbles/esm5/marbles.js 9:0-45
@ ./node_modules/rxjs-marbles/esm5/jasmine/index.js
@ ./src/app/app.component.spec.ts
@ ./src \.spec\.ts$
@ ./src/test.ts
ERROR in ./node_modules/rxjs-marbles/esm5/context-deprecated.js
Module not found: Error: Can't resolve 'rxjs/testing' in '/Users/armo/Code/rxjsmarbles/node_modules/rxjs-marbles/esm5'
@ ./node_modules/rxjs-marbles/esm5/context-deprecated.js 10:0-45
@ ./node_modules/rxjs-marbles/esm5/marbles.js
@ ./node_modules/rxjs-marbles/esm5/jasmine/index.js
@ ./src/app/app.component.spec.ts
@ ./src \.spec\.ts$
@ ./src/test.ts
ERROR in ./node_modules/rxjs-marbles/esm5/context-run.js
Module not found: Error: Can't resolve 'rxjs/testing' in '/Users/armo/Code/rxjsmarbles/node_modules/rxjs-marbles/esm5'
@ ./node_modules/rxjs-marbles/esm5/context-run.js 1:0-45
@ ./node_modules/rxjs-marbles/esm5/marbles.js
@ ./node_modules/rxjs-marbles/esm5/jasmine/index.js
@ ./src/app/app.component.spec.ts
@ ./src \.spec\.ts$
@ ./src/test.ts
ERROR in node_modules/rxjs-marbles/context.d.ts(1,22): error TS2305: Module '"/Users/armo/Code/rxjsmarbles/node_modules/rxjs/Rx"' has no exported member 'SchedulerLike'.
node_modules/rxjs-marbles/context.d.ts(2,31): error TS2307: Cannot find module 'rxjs/testing'.
node_modules/rxjs-marbles/types.d.ts(2,31): error TS2307: Cannot find module 'rxjs/testing'.
解决方案
rxjs-marbles
版本 3 和更高版本依赖于 RxJS 版本 6。
如果您使用的是 RxJS 版本 5,则需要使用rxjs-marbles
版本 2,其最新版本是2.4.1
.
如果您使用该版本,对于文档,您应该参考该版本分支中的 README,而不是master
.
推荐阅读
- java - 为什么我在 AmazonSQS 中收到 java.lang.NoClassDefFoundError?
- microsoft-graph-api - MS-Graph 和带附件的 sendmail 失败
- angular - 如何将 Ajax 获取请求转换为 Angular 7 http 获取请求
- apache-poi - 获取较低级别的 XML 对象以将图像插入到 Apache POI 中的图表中?
- kdb - 如何比较查询中的特殊字符串
- html - 更改导航栏文本颜色
- r - R如何创建一个新变量,该变量引用另一个数据框中的特定值
- algorithm - AC-3算法的时间复杂度
- sql-server - 无法将大型数据库附加到在 docker 容器进程中运行的 SQL Server 引擎
- python - 将 wordpress xml 文件导入 Python 项目