Effects testing example is not working
Minimal reproduction of the bug/regression with instructions:
Maybe something is wrong with my system, but the first example on the testing readme is not working. It shows a TypeScript error Type 'TestHotObservable' is not assignable to type 'Observable<any>'.
Just copy and paste the first example from https://github.com/ngrx/platform/blob/master/docs/effects/testing.md
Simplified, still showing the error:
import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { hot } from 'jasmine-marbles';
import { Observable } from 'rxjs';
describe('test', () => {
let actions: Observable<any>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [],
providers: [ provideMockActions(() => actions) ]
});
});
it('should work', () => {
actions = hot('--a-', { a: '' });
});
});
This triggers an error on the line actions = hot(...):
Type 'TestHotObservable' is not assignable to type 'Observable
'. Types of property 'source' are incompatible.
Expected behavior:
It should not have an error, or if this is an issue with jasmine-marbles, the example could be updated to reflect any necessary changes.
Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):
NgRx: 6.1.0 Angular: 6.1.3 Node: 9.5.0 RxJs: 6.2.2 jasmine-marbles: 0.3.1
I would be willing to submit a PR to fix this issue
[ ] Yes (Assistance is provided if you need help submitting a pull request) [x] No
It seems fine here. what version of TS are you using?
I've tried on 2.6.2 and 3.0.1, but both give the same result for me. If it works for you, I suppose it must be something with my setup. I'll take it to StackOverflow.
Could you create a repo? I could take a look.
I'm not using NgRx 6.1 😅 let me retry.
Still working, with TS 2.9.2
While making the repo, figured out it was some jasmine-marbles issue... seems like even though 0.3.* was in node_modules, it was still using 0.2.* somehow. Maybe VSCode was caching something? Shrug. Thanks anyhow!
I also am experiencing this issue using Webstorm 2018.02 with the following package versions:
"jasmine-marbles": "0.4.0",
"typescript": "2.7.2",
"rxjs": "6.2.1",
// ngrx
"@ngrx/core": "1.2.0",
"@ngrx/effects": "6.0.1",
"@ngrx/store": "6.0.1",
// angular
"@angular/common": "6.1.7",
"@angular/compiler": "6.1.7",
"@angular/core": "6.1.7",
// etc.
I'll check if it is indeed caused by caching done by editors
@michahell remove the @ngrx/core package.
Thanks, did not notice that package was legacy'ing around. Hmm, I checked, it is not due to caching in Webstorm nor to the relic package :(
ERROR in src/app/effects/app.effects.spec.ts(97,7): error TS2322: Type 'TestHotObservable' is not assignable to type 'Subject<any>'.
Property 'observers' is missing in type 'TestHotObservable'.
src/app/effects/app.effects.spec.ts(105,7): error TS2322: Type 'TestHotObservable' is not assignable to type 'Subject<any>'.
it does make sense, does it not, since TestHotObservable extends Observable, and Subject extends Observable. Different superclasses, no?
https://github.com/synapse-wireless-labs/jasmine-marbles/blob/master/src/test-observables.ts#L26
it seems that when you type actions like this: let actions: TestObservable, the first it() test does compile. the problem now, is that provideMockActions() expects an Observable as return value.
It seems that somehow, the jasmine-marble typing is.... or has become suboptimal :/
The example with ReplaySubject doesn't work either:
it('should work', () => {
actions = new ReplaySubject(1);
actions.next(MyActions.exampleAction());
effects.someSource$.subscribe(result => {
expect(result).toEqual(MyActions.exampleActionSuccess());
});
});
The expect statement is never called. This test would only pass, because the done callback is missing.