我目前想用 ngrx/effects 测试我的效果。我遵循了降价,但是当我想运行测试时出现错误。
Cannot find module 'rxjs/testing' from 'jasmine-marbles.umd.js'
这是我的代码(目前我没有做任何期望,我只想要我的测试运行):
import { TestBed } from '@angular/core/testing'
import { provideMockActions } from '@ngrx/effects/testing'
import { ReplaySubject } from 'rxjs/ReplaySubject'
import { hot, cold } from 'jasmine-marbles'
import { Observable } from 'rxjs/Observable'
import { VersionService } from '../../service/version/version.service'
import { DataEffects } from './data.effect'
import { RequestVersions, ReceiveVersions } from './data.action'
describe('My Effects', () => {
let versionService: VersionService
let effects: DataEffects
let actions: Observable<any>
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
// any modules needed
],
providers: [
DataEffects,
provideMockActions(() => actions),
{provide: VersionService, useValue: {
getVersions: jest.fn().mockReturnValueOnce({data: {versions: 'MOCKED_VERSION_RESULT'}})
}}
],
})
versionService = TestBed.get(VersionService)
effects = TestBed.get(DataEffects)
})
it('should work', () => {
const action = new RequestVersions()
const completion = new ReceiveVersions('MOCKED_VERSION_RESULT')
actions = hot('--a-', { a: action });
const expected = cold('--b', { b: completion })
})
}
这里是我的 package.json 的样子:
[...]
"dependencies": {
[... all @angular import ...]
"@ngrx/effects": "^5.2.0",
"@ngrx/store": "^5.2.0",
"@ngrx/store-devtools": "^5.2.0",
"bootstrap": "^4.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "1.6.7",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jest": "^22.1.4",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-marbles": "^0.3.0",
"jest": "^22.4.2",
"jest-junit": "^3.6.0",
"jest-preset-angular": "^5.2.0",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
[...]
任何人都可以在这件事上帮助我吗?