-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(effects): add user provided effects to EffectsModule.forFeature #2231
Merged
brandonroberts
merged 13 commits into
ngrx:master
from
leon-marzahn:feat/effects-injection-token
Mar 17, 2020
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a7f4b9e
feat(effects): add user provided effects to EffectsModule
2650bca
feat(effects): add user provided effects to EffectsModule
ab19722
Merge remote-tracking branch 'origin/feat/effects-injection-token' in…
3b6aaae
feat(effects): add user provided effects to EffectsModule
bf89bda
Merge branch 'master' into feat/effects-injection-token
9b73d66
feat(effects): add user provided effects to EffectsModule
889cee7
feat(effects): add user provided effects to EffectsModule
52290a4
feat(effects): add user provided effects to EffectsModule
407a57f
feat(effects): add user provided effects to EffectsModule
41df532
feat(effects): add user provided effects to EffectsModule
2955653
feat(effects): add user provided effects to EffectsModule
2b0215d
feat(effects): add user provided effects to EffectsModule
dca891c
Merge branch 'master' into feat/effects-injection-token
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,17 +1,19 @@ | ||
import { NgModuleFactoryLoader, NgModule } from '@angular/core'; | ||
import { NgModule, NgModuleFactoryLoader } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { | ||
RouterTestingModule, | ||
SpyNgModuleFactoryLoader, | ||
} from '@angular/router/testing'; | ||
import { Router } from '@angular/router'; | ||
import { Store, Action } from '@ngrx/store'; | ||
import { Action, Store } from '@ngrx/store'; | ||
import { | ||
EffectsModule, | ||
EffectSources, | ||
OnIdentifyEffects, | ||
OnInitEffects, | ||
ROOT_EFFECTS_INIT, | ||
OnIdentifyEffects, | ||
EffectSources, | ||
USER_PROVIDED_FEATURE_EFFECTS, | ||
USER_PROVIDED_ROOT_EFFECTS, | ||
} from '..'; | ||
|
||
describe('NgRx Effects Integration spec', () => { | ||
|
@@ -90,6 +92,56 @@ describe('NgRx Effects Integration spec', () => { | |
}); | ||
}); | ||
|
||
it('should execute user provided root effects', (done: DoneFn) => { | ||
TestBed.resetTestingModule(); | ||
TestBed.configureTestingModule({ | ||
imports: [EffectsModule.forRoot()], | ||
providers: [ | ||
{ | ||
provide: Store, | ||
useValue: { | ||
dispatch: jasmine.createSpy('dispatch'), | ||
}, | ||
}, | ||
RootUserProvidedEffect, | ||
{ | ||
provide: USER_PROVIDED_ROOT_EFFECTS, | ||
multi: true, | ||
useValue: [RootUserProvidedEffect], | ||
}, | ||
], | ||
}); | ||
|
||
const store = TestBed.get(Store) as Store<any>; | ||
dispatch = store.dispatch as jasmine.Spy; | ||
|
||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: '[RootUserProvidedEffect]: INIT', | ||
}); | ||
done(); | ||
}); | ||
|
||
it('should execute user provided feature effects', (done: DoneFn) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
let router: Router = TestBed.get(Router); | ||
const loader: SpyNgModuleFactoryLoader = TestBed.get(NgModuleFactoryLoader); | ||
|
||
loader.stubbedModules = { feature: FeatModuleWithUserProvidedEffects }; | ||
router.resetConfig([{ path: 'feature-path', loadChildren: 'feature' }]); | ||
|
||
router.navigateByUrl('/feature-path').then(() => { | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: '[FeatUserProvidedEffect]: INIT', | ||
}); | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: '[FeatUserProvidedEffect2]: INIT', | ||
}); | ||
expect(dispatch).toHaveBeenCalledWith({ | ||
type: '[FeatUserProvidedEffect3]: INIT', | ||
}); | ||
done(); | ||
}); | ||
}); | ||
|
||
class RootEffectWithInitAction implements OnInitEffects { | ||
ngrxOnInitEffects(): Action { | ||
return { type: '[RootEffectWithInitAction]: INIT' }; | ||
|
@@ -109,6 +161,24 @@ describe('NgRx Effects Integration spec', () => { | |
|
||
class RootEffectWithoutLifecycle {} | ||
|
||
class RootUserProvidedEffect implements OnInitEffects { | ||
public ngrxOnInitEffects(): Action { | ||
return { type: '[RootUserProvidedEffect]: INIT' }; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
imports: [EffectsModule.forRoot()], | ||
providers: [ | ||
{ | ||
provide: USER_PROVIDED_ROOT_EFFECTS, | ||
multi: true, | ||
useValue: [RootUserProvidedEffect], | ||
}, | ||
], | ||
}) | ||
class RootModuleWithUserProvidedEffects {} | ||
|
||
class FeatEffectWithInitAction implements OnInitEffects { | ||
ngrxOnInitEffects(): Action { | ||
return { type: '[FeatEffectWithInitAction]: INIT' }; | ||
|
@@ -128,8 +198,46 @@ describe('NgRx Effects Integration spec', () => { | |
constructor(private effectIdentifier: string) {} | ||
} | ||
|
||
class FeatUserProvidedEffect implements OnInitEffects { | ||
public ngrxOnInitEffects(): Action { | ||
return { type: '[FeatUserProvidedEffect]: INIT' }; | ||
} | ||
} | ||
|
||
class FeatUserProvidedEffect2 implements OnInitEffects { | ||
public ngrxOnInitEffects(): Action { | ||
return { type: '[FeatUserProvidedEffect2]: INIT' }; | ||
} | ||
} | ||
|
||
class FeatUserProvidedEffect3 implements OnInitEffects { | ||
public ngrxOnInitEffects(): Action { | ||
return { type: '[FeatUserProvidedEffect3]: INIT' }; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
imports: [EffectsModule.forRoot([])], | ||
imports: [EffectsModule.forRoot()], | ||
}) | ||
class FeatModuleWithForRoot {} | ||
|
||
@NgModule({ | ||
imports: [EffectsModule.forFeature()], | ||
providers: [ | ||
FeatUserProvidedEffect, | ||
FeatUserProvidedEffect2, | ||
FeatUserProvidedEffect3, | ||
{ | ||
provide: USER_PROVIDED_FEATURE_EFFECTS, | ||
multi: true, | ||
useValue: [FeatUserProvidedEffect, FeatUserProvidedEffect2], | ||
}, | ||
{ | ||
provide: USER_PROVIDED_FEATURE_EFFECTS, | ||
multi: true, | ||
useValue: [FeatUserProvidedEffect3], | ||
}, | ||
], | ||
}) | ||
class FeatModuleWithUserProvidedEffects {} | ||
}); |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of writing these tests, what about adding the providers in the
should dispatch init actions in the correct order
spec? This way, we also test the order of effects registrationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also create a simple unit test to verify the effect is added?
Something as: