Skip to content

Commit

Permalink
test(store): fix strictImmutability tests passing by default
Browse files Browse the repository at this point in the history
'NgRx' actions were passing tests by default as no case handled them in
the reducer. Adding cases to handle 'NgRx' actions exposed a futher
error in the tests. 'should not throw for NgRx actions' test was testing
and failing against an Unserializable state. The library allows NgRx
actions where the action is Unserializable so the 'should not throw for
NgRx actions' test was moved from State Serialization to Action
Serialization.
  • Loading branch information
donohoea committed Jul 6, 2021
1 parent abb0589 commit 6944383
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions modules/store/spec/runtime_checks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,6 @@ describe('Runtime checks:', () => {
flush();
}).not.toThrow();
}));

it('should not throw for NgRx actions', fakeAsync(() => {
const store = setupStore({ strictStateSerializability: true });

expect(() => {
store.dispatch(makeNgrxAction(invalidAction()));
flush();
}).not.toThrow();
}));
});

describe('Action Serialization:', () => {
Expand All @@ -172,6 +163,15 @@ describe('Runtime checks:', () => {
flush();
}).not.toThrow();
}));

it('should not throw for NgRx actions', fakeAsync(() => {
const store = setupStore({ strictActionSerializability: true });

expect(() => {
store.dispatch(makeNgrxAction(invalidAction()));
flush();
}).not.toThrow();
}));
});

describe('State Mutations', () => {
Expand Down Expand Up @@ -338,19 +338,31 @@ function reducerWithBugs(state: any = {}, action: any) {
invalidSerializationState: true,
invalid: new Date(),
};

case ErrorTypes.UnserializableAction: {
return {
invalidSerializationAction: true,
};
}

case '@ngrx ' + ErrorTypes.UnserializableAction: {
return {
invalidSerializationAction: true,
};
}

case ErrorTypes.MutateAction: {
action.foo = 'foo';
return {
invalidMutationAction: true,
};
}
case '@ngrx ' + ErrorTypes.MutateAction: {
action.foo = 'foo';
return {
invalidMutationAction: true,
};
}

case ErrorTypes.MutateState: {
state.invalidMutationState = true;
Expand Down

0 comments on commit 6944383

Please sign in to comment.