From 4329f174f1ec300f87c86b57e8011ecf348a357d Mon Sep 17 00:00:00 2001 From: ijz953 Date: Wed, 24 Apr 2019 07:17:23 -0400 Subject: [PATCH] docs: fix code-example closing tag in store testing guide --- .../app/books/effects/collection.effects.ts | 31 +++++++++++++++++-- .../ngrx.io/content/guide/store/testing.md | 4 +-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/projects/example-app/src/app/books/effects/collection.effects.ts b/projects/example-app/src/app/books/effects/collection.effects.ts index 942e32c97f..583998df82 100644 --- a/projects/example-app/src/app/books/effects/collection.effects.ts +++ b/projects/example-app/src/app/books/effects/collection.effects.ts @@ -1,7 +1,14 @@ 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, @@ -9,6 +16,9 @@ import { 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 { /** @@ -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 ) {} } diff --git a/projects/ngrx.io/content/guide/store/testing.md b/projects/ngrx.io/content/guide/store/testing.md index c9bdd7b043..865f434a44 100644 --- a/projects/ngrx.io/content/guide/store/testing.md +++ b/projects/ngrx.io/content/guide/store/testing.md @@ -68,9 +68,9 @@ describe('Auth Guard', () => { Usage: - + - + 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`.