Last active
February 23, 2025 02:51
-
-
Save ThomasBurleson/d2d62c8086e562621e597ba330aa38d6 to your computer and use it in GitHub Desktop.
Revisions
-
ThomasBurleson revised this gist
Aug 12, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -11,9 +11,9 @@ import { NxModule } from '@nrwl/nx'; * NgRx feature slice for 'Cars' state */ import { LoadCars, CarsLoaded } from './cars.actions'; import { CarsEffects } from './cars.effects'; import { CarsFacade } from './cars.facade'; import { CarsState, Entity, initialState, carsReducer } from './cars.reducer'; /** * The full-app NgRx state only has a 'cars' feature slice -
ThomasBurleson revised this gist
Aug 12, 2018 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,6 @@ import { NxModule } from '@nrwl/nx'; */ import { LoadCars, CarsLoaded } from './cars.actions'; import { CarsState, Entity, initialState, carsReducer } from './cars.reducer'; import { CarsEffects } from './cars.effects'; import { CarsFacade } from './cars.facade'; -
ThomasBurleson revised this gist
Aug 12, 2018 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -88,9 +88,10 @@ describe('CarsFacade', () => { }); /** * Use `CarsLoaded` to manually submit list for state management and * test that our observable is properly streaming data changes. */ it('allCars$ should return the current list', async (done) => { try { let list = await readFirst(facade.allCars$); let isLoaded = await readFirst(facade.loaded$); -
ThomasBurleson revised this gist
Aug 12, 2018 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -98,7 +98,10 @@ describe('CarsFacade', () => { expect(list.length).toBe(0); expect(isLoaded).toBe(false); // Here we are testing our NgRx actions, reducers, and selectors. // Simulate results of a loadAll() and add two (2) cars to our NgRx 'cars' state. store.dispatch(new CarsLoaded([ createCars('AAA'), createCars('BBB') ])); -
ThomasBurleson revised this gist
Aug 12, 2018 . 1 changed file with 4 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -72,17 +72,13 @@ describe('CarsFacade', () => { expect(list.length).toBe(0); // initially empty expect(isLoaded).toBe(false); // initially not loaded facade.loadAll(); // In our case loadAll() always returns an empty array. list = await readFirst(facade.allCars$); isLoaded = await readFirst(facade.loaded$); expect(isLoaded).toBe(true); // data load completed expect(list.length).toBe(0); done(); @@ -102,9 +98,7 @@ describe('CarsFacade', () => { expect(list.length).toBe(0); expect(isLoaded).toBe(false); store.dispatch(new CarsLoaded([ // Add two (2) cars to our NgRx 'cars' state createCars('AAA'), createCars('BBB') ])); -
ThomasBurleson revised this gist
Aug 12, 2018 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,9 +16,11 @@ import { CarsState, Entity, initialState, carsReducer } from './cars.reducer'; import { CarsEffects } from './cars.effects'; import { CarsFacade } from './cars.facade'; /** * The full-app NgRx state only has a 'cars' feature slice */ interface TestSchema { 'cars' : CarsState } describe('CarsFacade', () => { @@ -29,7 +31,7 @@ describe('CarsFacade', () => { beforeEach(() => { createCars = ( id:string, name = '' ): Entity => ({ id, name: name ? `name-${id}` : id }); }); -
ThomasBurleson revised this gist
Aug 12, 2018 . 1 changed file with 7 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,16 +10,15 @@ import { NxModule } from '@nrwl/nx'; /** * NgRx feature slice for 'Cars' state */ import { LoadCars, CarsLoaded } from './cars.actions'; import { CarsState, Entity, initialState, carsReducer } from './cars.reducer'; import { CarsEffects } from './cars.effects'; import { CarsFacade } from './cars.facade'; interface TestSchema { 'cars' : CarsState } describe('CarsFacade', () => { @@ -34,12 +33,12 @@ describe('CarsFacade', () => { }); }); describe('used in NgModule', async (done) => { beforeEach(() => { @NgModule({ imports: [ StoreModule.forFeature('cars', carsReducer, { initialState }), EffectsModule.forFeature([CarsEffects]) ], providers: [CarsFacade] -
ThomasBurleson revised this gist
Aug 12, 2018 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -71,16 +71,18 @@ describe('CarsFacade', () => { expect(list.length).toBe(0); // initially empty expect(isLoaded).toBe(false); // initially not loaded // Note: the default Nx schematic-generated logic in `cars.effects.ts` // will simulate a load and return an empty array. Developers // must customize with their own logic. facade.loadAll(); list = await readFirst(facade.allCars$); isLoaded = await readFirst(facade.loaded$); expect(isLoaded).toBe(true); // data load completed expect(list.length).toBe(0); done(); } catch (err) { -
ThomasBurleson revised this gist
Aug 12, 2018 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -99,6 +99,8 @@ describe('CarsFacade', () => { expect(list.length).toBe(0); expect(isLoaded).toBe(false); // Update our 'cars' state with two (2) cars loaded store.dispatch(new CarsLoaded([ createCars('AAA'), createCars('BBB') -
ThomasBurleson revised this gist
Aug 12, 2018 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -69,10 +69,12 @@ describe('CarsFacade', () => { let list = await readFirst(facade.allCars$); let isLoaded = await readFirst(facade.loaded$); expect(list.length).toBe(0); // initially empty expect(isLoaded).toBe(false); // initially not loaded // Note: the default Nx schematic-generated logic in `cars.effects.ts` // will simulate a load and return an empty array. facade.loadAll(); list = await readFirst(facade.allCars$); isLoaded = await readFirst(facade.loaded$); -
ThomasBurleson created this gist
Aug 11, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,118 @@ import { NgModule } from '@angular/core'; import { TestBed } from '@angular/core/testing'; import { readFirst } from '@nrwl/nx/testing'; import { EffectsModule } from '@ngrx/effects'; import { StoreModule, Store } from '@ngrx/store'; import { NxModule } from '@nrwl/nx'; /** * NgRx feature slice for 'Cars' state */ import { CarsQuery } from './Cars.selectors'; import { LoadCars, CarsLoaded } from './Cars.actions'; import { CarsState, Entity, initialState, CarsReducer } from './Cars.reducer'; import { CarsEffects } from './Cars.effects'; import { CarsFacade } from './Cars.facade'; interface TestSchema { 'Cars' : CarsState } describe('CarsFacade', () => { let facade: CarsFacade; let store: Store<TestSchema>; let createCars; beforeEach(() => { createCars = ( id:string, name = '' ): Entity => ({ id, name: name || `name-${id}` }); }); describe('used in NgModule', () => { beforeEach(() => { @NgModule({ imports: [ StoreModule.forFeature('Cars', CarsReducer, { initialState }), EffectsModule.forFeature([CarsEffects]) ], providers: [CarsFacade] }) class CustomFeatureModule {} @NgModule({ imports: [ NxModule.forRoot(), StoreModule.forRoot({}), EffectsModule.forRoot([]), CustomFeatureModule, ] }) class RootModule {} TestBed.configureTestingModule({ imports: [RootModule] }); store = TestBed.get(Store); facade = TestBed.get(CarsFacade); }); /** * The initially generated facade::loadAll() returns empty array */ it('loadAll() should return empty list with loaded == true', async (done) => { try { let list = await readFirst(facade.allCars$); let isLoaded = await readFirst(facade.loaded$); expect(list.length).toBe(0); expect(isLoaded).toBe(false); facade.loadAll(); list = await readFirst(facade.allCars$); isLoaded = await readFirst(facade.loaded$); expect(list.length).toBe(0); expect(isLoaded).toBe(true); done(); } catch (err) { done.fail(err); } }); /** * Use `CarsLoaded` to manually submit list for state management */ it('allCars$ should return the loaded list; and loaded flag == true', async (done) => { try { let list = await readFirst(facade.allCars$); let isLoaded = await readFirst(facade.loaded$); expect(list.length).toBe(0); expect(isLoaded).toBe(false); store.dispatch(new CarsLoaded([ createCars('AAA'), createCars('BBB') ])); list = await readFirst(facade.allCars$); isLoaded = await readFirst(facade.loaded$); expect(list.length).toBe(2); expect(isLoaded).toBe(true); done(); } catch (err) { done.fail(err); } }); }); });