Skip to content

Commit

Permalink
docs: fix code-example closing tag in store testing guide
Browse files Browse the repository at this point in the history
  • Loading branch information
ijz953 committed Apr 24, 2019
1 parent 15b975a commit 4329f17
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
31 changes: 29 additions & 2 deletions projects/example-app/src/app/books/effects/collection.effects.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType, createEffect } from '@ngrx/effects';
import { defer, of } from 'rxjs';
import { catchError, map, mergeMap, switchMap } from 'rxjs/operators';
import {
catchError,
map,
mergeMap,
switchMap,
withLatestFrom,
tap,
} from 'rxjs/operators';
import { Book } from '@example-app/books/models/book';
import {
CollectionApiActions,
CollectionPageActions,
SelectedBookPageActions,
} from '@example-app/books/actions';
import { BookStorageService } from '@example-app/core/services';
import * as fromBooks from '@example-app/books/reducers';
import { select, Store } from '@ngrx/store';

@Injectable()
export class CollectionEffects {
/**
Expand Down Expand Up @@ -66,8 +76,25 @@ export class CollectionEffects {
)
);

addBookToCollectionSuccess$ = createEffect(
() =>
this.actions$.pipe(
ofType(CollectionApiActions.addBookSuccess),
withLatestFrom(this.store.pipe(select(fromBooks.getCollectionBookIds))),
tap(([, bookCollection]) => {
if (bookCollection.length === 1) {
window.alert('Congrats on adding your first book!');
} else {
window.alert('You have added book number ' + bookCollection.length);
}
})
),
{ dispatch: false }
);

constructor(
private actions$: Actions,
private storageService: BookStorageService
private storageService: BookStorageService,
private store: Store<fromBooks.State>
) {}
}
4 changes: 2 additions & 2 deletions projects/ngrx.io/content/guide/store/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ describe('Auth Guard', () => {

Usage:

<code-example header="auth-guard.service.ts" path="testing-store/src/app/auth-guard.service.ts">
<code-example header="auth-guard.service.ts" path="testing-store/src/app/auth-guard.service.ts"></code-example>

<code-example header="auth-guard.service.spec.ts" path="testing-store/src/app/auth-guard.service.spec.ts">
<code-example header="auth-guard.service.spec.ts" path="testing-store/src/app/auth-guard.service.spec.ts"></code-example>

In this example, we mock the `getLoggedIn` selector by using `overrideSelector`, passing in the `getLoggedIn` selector with a default mocked return value of `false`. In the second test, we use `setResult()` to update the mock selector to return `true`.

Expand Down

0 comments on commit 4329f17

Please sign in to comment.