Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions modules/schematics/src/store/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,27 @@ describe('Store Schematic', () => {
);
expect(content).toMatch(/export interface FeatureState {/);
});

it('should fail if a feature state name is not specified', () => {
const options = {
...defaultOptions,
name: undefined,
root: false,
};

expect(() => {
schematicRunner.runSchematic('store', options, appTree);
}).toThrowError('Please provide a name for the feature state');
});

it('should pass if a root state name is not specified', () => {
const options = {
...defaultOptions,
name: undefined,
};

expect(() => {
schematicRunner.runSchematic('store', options, appTree);
}).not.toThrow();
});
});
6 changes: 5 additions & 1 deletion modules/schematics/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,13 @@ function addImportToNgModule(options: StoreOptions): Rule {

export default function(options: StoreOptions): Rule {
return (host: Tree, context: SchematicContext) => {
if (!options.name && !options.root) {
throw new Error(`Please provide a name for the feature state`);
}

options.path = getProjectPath(host, options);

const parsedPath = parseName(options.path, options.name);
const parsedPath = parseName(options.path, options.name || '');
options.name = parsedPath.name;
options.path = parsedPath.path;

Expand Down
7 changes: 6 additions & 1 deletion projects/example-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ import { AppRoutingModule } from '@example-app/app-routing.module';
* meta-reducer. This returns all providers for an @ngrx/store
* based application.
*/
StoreModule.forRoot(reducers, { metaReducers }),
StoreModule.forRoot(reducers, {
metaReducers,
runtimeChecks: {
strictImmutability: true,
},
}),

/**
* @ngrx/router-store keeps router state up-to-date in the store.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ describe('Login Page', () => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
StoreModule.forRoot({
auth: combineReducers(fromAuth.reducers),
}),
StoreModule.forRoot(
{
auth: combineReducers(fromAuth.reducers),
},
{
runtimeChecks: {
strictImmutability: true,
},
}
),
MatInputModule,
MatCardModule,
ReactiveFormsModule,
Expand Down
6 changes: 1 addition & 5 deletions projects/example-app/src/app/auth/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import * as fromRoot from '@example-app/reducers';
import * as fromAuth from '@example-app/auth/reducers/auth.reducer';
import * as fromLoginPage from '@example-app/auth/reducers/login-page.reducer';
import { AuthApiActions } from '@example-app/auth/actions';

export interface AuthState {
status: fromAuth.State;
Expand All @@ -17,10 +16,7 @@ export interface State extends fromRoot.State {
auth: AuthState;
}

export const reducers: ActionReducerMap<
AuthState,
AuthApiActions.AuthApiActionsUnion
> = {
export const reducers: ActionReducerMap<AuthState, any> = {
status: fromAuth.reducer,
loginPage: fromLoginPage.reducer,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ describe('Collection Page', () => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
StoreModule.forRoot({
books: combineReducers(fromBooks.reducers),
}),
StoreModule.forRoot(
{
books: combineReducers(fromBooks.reducers),
},
{
runtimeChecks: {
strictImmutability: true,
},
}
),
MatCardModule,
MatInputModule,
RouterTestingModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ describe('Find Book Page', () => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
StoreModule.forRoot({
books: combineReducers(fromBooks.reducers),
}),
StoreModule.forRoot(
{
books: combineReducers(fromBooks.reducers),
},
{
runtimeChecks: {
strictImmutability: true,
},
}
),
RouterTestingModule,
MatInputModule,
MatCardModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ describe('Selected Book Page', () => {
TestBed.configureTestingModule({
imports: [
NoopAnimationsModule,
StoreModule.forRoot({
books: combineReducers(fromBooks.reducers),
}),
StoreModule.forRoot(
{
books: combineReducers(fromBooks.reducers),
},
{
runtimeChecks: {
strictImmutability: true,
},
}
),
MatCardModule,
],
declarations: [
Expand Down