Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('load question of the day', () => {
const completion = new QuestionActions().getQuestionOfTheDaySuccess(question);
// not sure this best way to emulate it, this can be converted into utility function
// here to test effect which use router navigation action we are manually mocking it
// this by pass ngrx route-store and router all together and only test effect
const routerState: RouterStateUrl = { url: '/dashboard', queryParams: {}, params: {} };
const event: RoutesRecognized = new RoutesRecognized(1, '/dashboard', '', null);
const payload: RouterNavigationPayload = {
routerState,
event
};
const action: RouterNavigationAction = {
type: ROUTER_NAVIGATION,
payload
};
actions$ = hot('-a---', { a: action });
const response = cold('-a|', { a: question });
const expected = cold('--b', { b: completion });
questionService.getQuestionOfTheDay = jest.fn(() => {
console.log('mocked getQuestionOfTheDay');
return response
});
it('get all blogs', () => {
const obj = TEST_DATA.blog;
// const action = new LoadBlogs();
const routerState: RouterStateUrl = { url: '/', queryParams: {}, params: {} };
const event: RoutesRecognized = new RoutesRecognized(1, '/', '', null);
const payload: RouterNavigationPayload = {
routerState,
event
};
const action: RouterNavigationAction = {
type: ROUTER_NAVIGATION,
payload
};
const completion = new LoadBlogsSuccess(TEST_DATA.blog);
actions$ = hot('-a----', { a: action });
const response = cold('-a|', { a: obj });
const expected = cold('--b', { b: completion });
socialService.loadBlogs = jest.fn(() => response);
expect(effects.getBlogs$).toBeObservable(expected);
});
private dispatchRouterNavigation(
lastRoutesRecognized: RoutesRecognized
): void {
const nextRouterState = this.serializer.serialize(
lastRoutesRecognized.state
);
this.dispatchRouterAction(ROUTER_NAVIGATION, {
routerState: nextRouterState,
event: new RoutesRecognized(
lastRoutesRecognized.id,
lastRoutesRecognized.url,
lastRoutesRecognized.urlAfterRedirects,
nextRouterState
),
});
}
private dispatchRouterNavigation(): void {
const nextRouterState = this._serializer.serialize(this._lastRoutesRecognized.state);
this.dispatchRouterAction(
new RouterNavigation(
nextRouterState,
new RoutesRecognized(
this._lastRoutesRecognized.id,
this._lastRoutesRecognized.url,
this._lastRoutesRecognized.urlAfterRedirects,
nextRouterState
),
this._trigger
)
);
}