Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(effects): use provideMockActions outside of the TestBed
- Loading branch information
1 parent
b128dee
commit 63a4cb1
Showing
2 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { of } from 'rxjs'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { provideMockActions } from '@ngrx/effects/testing'; | ||
import { Actions } from '@ngrx/effects'; | ||
import { Injector } from '@angular/core'; | ||
|
||
describe('Mock Actions', () => { | ||
describe('with TestBed', () => { | ||
it('should provide Actions from source', (done) => { | ||
TestBed.configureTestingModule({ | ||
providers: [provideMockActions(of({ type: 'foo' }))], | ||
}); | ||
|
||
const actions$ = TestBed.inject(Actions); | ||
actions$.subscribe((action) => { | ||
expect(action.type).toBe('foo'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should provide Actions from factory', (done) => { | ||
TestBed.configureTestingModule({ | ||
providers: [provideMockActions(() => of({ type: 'bar' }))], | ||
}); | ||
|
||
const actions$ = TestBed.inject(Actions); | ||
actions$.subscribe((action) => { | ||
expect(action.type).toBe('bar'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('with Injector', () => { | ||
it('should provide Actions from source', (done) => { | ||
const injector = Injector.create({ | ||
providers: [provideMockActions(of({ type: 'foo' }))], | ||
}); | ||
|
||
const actions$ = injector.get(Actions); | ||
actions$.subscribe((action) => { | ||
expect(action.type).toBe('foo'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should provide Actions from factory', (done) => { | ||
const injector = Injector.create({ | ||
providers: [provideMockActions(() => of({ type: 'bar' }))], | ||
}); | ||
|
||
const actions$ = injector.get(Actions); | ||
actions$.subscribe((action) => { | ||
expect(action.type).toBe('bar'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters