From 61b1ac7bc388d575ff09cea5b06c8aed12595e93 Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Thu, 29 Apr 2021 04:02:03 +0200 Subject: [PATCH] fix(schematics): assert empty as action observable (#3005) Closes #2931 --- .../__name@dasherize__.effects.ts.template | 8 ++++---- modules/schematics/src/effect/index.spec.ts | 8 +++++--- modules/schematics/src/feature/index.spec.ts | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.ts.template b/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.ts.template index 549fe117c6..45efe8f9f5 100644 --- a/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.ts.template +++ b/modules/schematics/src/effect/files/__name@dasherize@if-flat__/__name@dasherize__.effects.ts.template @@ -1,12 +1,12 @@ import { Injectable } from '@angular/core'; import { Actions, <%= effectMethod %><% if (feature) { %>, ofType<% } %> } from '@ngrx/effects'; <% if (feature && api) { %>import { catchError, map, concatMap } from 'rxjs/operators'; -import { EMPTY, of } from 'rxjs'; +import { Observable, EMPTY, of } from 'rxjs'; <% if (!creators) {%>import { Load<%= classify(name) %>sFailure, Load<%= classify(name) %>sSuccess, <%= classify(name) %>ActionTypes, <%= classify(name) %>Actions } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %> <% if (creators) {%>import * as <%= classify(name) %>Actions from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %> <% } %> <% if (feature && !api) { %>import { concatMap } from 'rxjs/operators'; -import { EMPTY } from 'rxjs'; +import { Observable, EMPTY } from 'rxjs'; <% if (!creators) {%>import { <%= classify(name) %>ActionTypes, <%= classify(name) %>Actions } from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %> <% if (creators) {%>import * as <%= classify(name) %>Actions from '<%= featurePath(group, flat, "actions", dasherize(name)) %><%= dasherize(name) %>.actions';<% } %> <% } %> @@ -38,13 +38,13 @@ export class <%= classify(name) %>Effects { <%= effectStart %> ofType(<%= classify(name) %>ActionTypes.Load<%= classify(name) %>s), /** An EMPTY observable only emits completion. Replace with your own observable API request */ - concatMap(() => EMPTY) + concatMap(() => EMPTY as Observable<{ type: string }>) <%= effectEnd %> <% } else if (feature && !api && creators) { %> <%= effectStart %> ofType(<%= classify(name) %>Actions.load<%= classify(name) %>s), /** An EMPTY observable only emits completion. Replace with your own observable API request */ - concatMap(() => EMPTY) + concatMap(() => EMPTY as Observable<{ type: string }>) <%= effectEnd %> <% } %> <% if (feature && !creators) { %> diff --git a/modules/schematics/src/effect/index.spec.ts b/modules/schematics/src/effect/index.spec.ts index 066175464f..de24f6f48f 100644 --- a/modules/schematics/src/effect/index.spec.ts +++ b/modules/schematics/src/effect/index.spec.ts @@ -321,14 +321,16 @@ describe('Effect Schematic', () => { /import { Actions, Effect, ofType } from '@ngrx\/effects';/ ); expect(content).toMatch(/import { concatMap } from 'rxjs\/operators';/); - expect(content).toMatch(/import { EMPTY } from 'rxjs';/); + expect(content).toMatch(/import { Observable, EMPTY } from 'rxjs';/); expect(content).toMatch( /import { FooActionTypes, FooActions } from '\.\/foo.actions';/ ); expect(content).toMatch(/export class FooEffects/); expect(content).toMatch(/loadFoos\$ = this\.actions\$.pipe\(/); expect(content).toMatch(/ofType\(FooActionTypes\.LoadFoos\)/); - expect(content).toMatch(/concatMap\(\(\) => EMPTY\)/); + expect(content).toMatch( + /concatMap\(\(\) => EMPTY as Observable<\{ type: string \}>\)/ + ); expect(content).toMatch( /constructor\(private actions\$: Actions\) {}/ @@ -371,7 +373,7 @@ describe('Effect Schematic', () => { expect(content).toMatch( /import { catchError, map, concatMap } from 'rxjs\/operators';/ ); - expect(content).toMatch(/import { EMPTY, of } from 'rxjs';/); + expect(content).toMatch(/import { Observable, EMPTY, of } from 'rxjs';/); expect(content).toMatch( /import { LoadFoosFailure, LoadFoosSuccess, FooActionTypes, FooActions } from '\.\/foo.actions';/ ); diff --git a/modules/schematics/src/feature/index.spec.ts b/modules/schematics/src/feature/index.spec.ts index 83c2f4c426..33c3380290 100644 --- a/modules/schematics/src/feature/index.spec.ts +++ b/modules/schematics/src/feature/index.spec.ts @@ -229,7 +229,9 @@ describe('Feature Schematic', () => { expect(fileContent).toMatch( /import { catchError, map, concatMap } from 'rxjs\/operators';/ ); - expect(fileContent).toMatch(/import { EMPTY, of } from 'rxjs';/); + expect(fileContent).toMatch( + /import { Observable, EMPTY, of } from 'rxjs';/ + ); expect(fileContent).toMatch( /import \* as FooActions from '.\/foo.actions';/ );