Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Last active January 24, 2018 12:17
Show Gist options
  • Save NetanelBasal/ea61c202ba0713f049ae85f4bc159ca2 to your computer and use it in GitHub Desktop.
Save NetanelBasal/ea61c202ba0713f049ae85f4bc159ca2 to your computer and use it in GitHub Desktop.
describe('PostsEffects', () => {
let runner, postsEffects, postsService;
beforeEach(() => TestBed.configureTestingModule({
imports: [
EffectsTestingModule
],
providers: [
PostsEffects,
{
provide: PostsService,
useValue: jasmine.createSpyObj('postsService', ['get'])
}
]
}));
beforeEach(() => {
runner = TestBed.get(EffectsRunner);
postsEffects = TestBed.get(PostsEffects);
postsService = TestBed.get(PostsService);
});
describe('get$', () => {
it('should return a GET_POSTS_SUCCESS action, on success', () => {
const postsToReturn = [{ id: 1 }];
postsService.get.and.returnValue(Observable.of(postsToReturn));
const expectedResult = getPostsSuccess(postsToReturn);
runner.queue(getPosts());
postsEffects.get$.subscribe(result => {
expect(result).toEqual(expectedResult);
});
});
it('should return a GET_POSTS_FAIL action, on error, after the de-bounce', fakeAsync(function () {
const expectedResult = getPostsFail('error');
let resultFromEffect = null;
postsService.get.and.returnValue(Observable.throw('error'));
runner.queue(getPosts());
postsEffects.posts$.subscribe(result => result = resultFromEffect);
tick(399);
expect(result).toEqual(null);
tick(400);
expect(result).toEqual(expectedResult);
}));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment