diff --git a/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.ts b/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.ts index d3d6dfb92c..f2c2331e71 100644 --- a/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.ts +++ b/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.ts @@ -1,12 +1,12 @@ import { Injectable } from '@angular/core'; -import { Actions, Effect } from '@ngrx/effects'; -<% if(feature) { %>import { <%= classify(name) %>Actions, <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %> +import { Actions, Effect<% if (feature) { %>, ofType<% } %> } from '@ngrx/effects'; +<% if (feature) { %>import { <%= classify(name) %>ActionTypes } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %> @Injectable() export class <%= classify(name) %>Effects { -<% if(feature) { %> +<% if (feature) { %> @Effect() - effect$ = this.actions$.ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s); + loadFoos$ = this.actions$.pipe(ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s)); <% } %> constructor(private actions$: Actions) {} } diff --git a/modules/schematics/src/effect/index.spec.ts b/modules/schematics/src/effect/index.spec.ts index 18233cd363..29409357ce 100644 --- a/modules/schematics/src/effect/index.spec.ts +++ b/modules/schematics/src/effect/index.spec.ts @@ -37,7 +37,7 @@ describe('Effect Schematic', () => { appTree = createWorkspace(schematicRunner, appTree); }); - it('should create an effect', () => { + it('should create an effect with a spec file', () => { const options = { ...defaultOptions }; const tree = schematicRunner.runSchematic('effect', options, appTree); @@ -215,7 +215,45 @@ describe('Effect Schematic', () => { ); expect(content).toMatch( - /import\ \{\ FooActions,\ FooActionTypes\ }\ from\ \'\.\.\/\.\.\/actions\/foo\/foo\.actions';/ + /import \{ FooActionTypes } from \'\.\.\/\.\.\/actions\/foo\/foo\.actions';/ + ); + }); + + it('should create an effect that describes a source of actions within a feature', () => { + const options = { ...defaultOptions, feature: true }; + + const tree = schematicRunner.runSchematic('effect', options, appTree); + const content = tree.readContent( + `${projectPath}/src/app/foo/foo.effects.ts` + ); + expect(content).toMatch( + /import { Actions, Effect, ofType } from '@ngrx\/effects';/ + ); + expect(content).toMatch( + /import { FooActionTypes } from '\.\/foo.actions';/ + ); + expect(content).toMatch(/export class FooEffects/); + expect(content).toMatch( + /loadFoos\$ = this\.actions\$.pipe\(ofType\(FooActionTypes\.LoadFoos\)\);/ + ); + }); + + it('should create an effect that does not define a source of actions within the root', () => { + const options = { ...defaultOptions, root: true }; + + const tree = schematicRunner.runSchematic('effect', options, appTree); + const content = tree.readContent( + `${projectPath}/src/app/foo/foo.effects.ts` + ); + expect(content).toMatch( + /import { Actions, Effect } from '@ngrx\/effects';/ + ); + expect(content).not.toMatch( + /import { FooActionTypes } from '\.\/foo.actions';/ + ); + expect(content).toMatch(/export class FooEffects/); + expect(content).not.toMatch( + /loadFoos\$ = this\.actions\$.pipe\(ofType\(FooActionTypes\.LoadFoos\)\);/ ); }); });