-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(StoreDevTools): out of bounds when actions are filtered (#1532)
Closes #1522
- Loading branch information
1 parent
e17a787
commit d532979
Showing
4 changed files
with
223 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,96 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { StoreModule, Store, ActionsSubject } from '@ngrx/store'; | ||
import { StoreDevtoolsModule, StoreDevtools } from '@ngrx/store-devtools'; | ||
import { StoreModule, Store, Action } from '@ngrx/store'; | ||
import { | ||
StoreDevtoolsModule, | ||
StoreDevtools, | ||
StoreDevtoolsOptions, | ||
} from '@ngrx/store-devtools'; | ||
|
||
describe('Devtools Integration', () => { | ||
let store: Store<any>; | ||
|
||
@NgModule({ | ||
imports: [StoreModule.forFeature('a', (state: any, action: any) => state)], | ||
}) | ||
class EagerFeatureModule {} | ||
|
||
@NgModule({ | ||
imports: [ | ||
StoreModule.forRoot({}), | ||
EagerFeatureModule, | ||
StoreDevtoolsModule.instrument(), | ||
], | ||
}) | ||
class RootModule {} | ||
|
||
beforeEach(() => { | ||
function setup(options: Partial<StoreDevtoolsOptions> = {}) { | ||
@NgModule({ | ||
imports: [ | ||
StoreModule.forFeature('a', (state: any, action: any) => state), | ||
], | ||
}) | ||
class EagerFeatureModule {} | ||
|
||
@NgModule({ | ||
imports: [ | ||
StoreModule.forRoot({}), | ||
EagerFeatureModule, | ||
StoreDevtoolsModule.instrument(options), | ||
], | ||
}) | ||
class RootModule {} | ||
|
||
TestBed.configureTestingModule({ | ||
imports: [RootModule], | ||
}); | ||
|
||
const store = TestBed.get(Store) as Store<any>; | ||
const devtools = TestBed.get(StoreDevtools) as StoreDevtools; | ||
return { store, devtools }; | ||
} | ||
|
||
afterEach(() => { | ||
const devtools = TestBed.get(StoreDevtools) as StoreDevtools; | ||
devtools.reset(); | ||
}); | ||
|
||
it('should load the store eagerly', () => { | ||
let error = false; | ||
|
||
try { | ||
let store = TestBed.get(Store); | ||
const { store } = setup(); | ||
store.subscribe(); | ||
} catch (e) { | ||
error = true; | ||
} | ||
|
||
expect(error).toBeFalsy(); | ||
}); | ||
|
||
it('should not throw if actions are ignored', (done: any) => { | ||
const { store, devtools } = setup({ | ||
predicate: (_, { type }: Action) => type !== 'FOO', | ||
}); | ||
store.subscribe(); | ||
devtools.dispatcher.subscribe((action: Action) => { | ||
if (action.type === 'REFRESH') { | ||
done(); | ||
} | ||
}); | ||
store.dispatch({ type: 'FOO' }); | ||
devtools.refresh(); | ||
}); | ||
|
||
it('should not throw if actions are blacklisted', (done: any) => { | ||
const { store, devtools } = setup({ | ||
actionsBlacklist: ['FOO'], | ||
}); | ||
store.subscribe(); | ||
devtools.dispatcher.subscribe((action: Action) => { | ||
if (action.type === 'REFRESH') { | ||
done(); | ||
} | ||
}); | ||
store.dispatch({ type: 'FOO' }); | ||
devtools.refresh(); | ||
}); | ||
|
||
it('should not throw if actions are whitelisted', (done: any) => { | ||
const { store, devtools } = setup({ | ||
actionsWhitelist: ['BAR'], | ||
}); | ||
store.subscribe(); | ||
devtools.dispatcher.subscribe((action: Action) => { | ||
if (action.type === 'REFRESH') { | ||
done(); | ||
} | ||
}); | ||
store.dispatch({ type: 'FOO' }); | ||
devtools.refresh(); | ||
}); | ||
}); |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters