Skip to content
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

Reducers can occasionally receive actions without a type #44

Merged
merged 10 commits into from
Feb 15, 2018

Conversation

lucax88x
Copy link
Contributor

@lucax88x lucax88x commented Feb 7, 2018

it happens only on specs, when you are testing for empty states to return the default state

(example: https://github.com/ngrx/platform/blob/master/example-app/app/books/reducers/books.spec.ts#L22)

@MrWolfZ
Copy link
Owner

MrWolfZ commented Feb 10, 2018

Can you please target develop instead of master? Also, please change the commit messages to use the type prefixes as defined by the Angular contribution guidelines?

Copy link
Owner

@MrWolfZ MrWolfZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some review comments. Some of them might seem a bit pedantic (and they might just be that ;) ), however, I try to keep the whole codebase as consistent as possible.

describe('action', () => {
it('should return true if type is ngrx/forms/', () => {
expect(isNgrxFormsAction({ type: 'ngrx/forms/' })).toBeTruthy();
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to be consistent with the formatting of the rest of the codebase, i.e. leave a blank line between each test.


describe('action', () => {
it('should return true if type is ngrx/forms/', () => {
expect(isNgrxFormsAction({ type: 'ngrx/forms/' })).toBeTruthy();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You expect the return value to be true, not just any truthy value, therefore you should assert on the concrete value (same for the other tests).

@@ -0,0 +1,16 @@
import { isNgrxFormsAction } from './actions';

describe('action', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are testing a concrete function, so you should use its name for the describe. Also, don't write the name as a string but instead access the name property of the function.

src/actions.ts Outdated
@@ -334,5 +334,5 @@ export type Actions<TValue> =
;

export function isNgrxFormsAction(action: Action) {
return action.type.startsWith('ngrx/forms/');
return action.type && action.type.startsWith('ngrx/forms/');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR would be the perfect chance to extract the prefix into a constant and use that everywhere. However, this is optional.

@lucax88x
Copy link
Contributor Author

That's perfectly understandable and instead means that you care of the repository ;) will do it soon.

@lucax88x lucax88x changed the base branch from master to develop February 12, 2018 14:33
@lucax88x
Copy link
Contributor Author

should be fine now.

ps: I extracted the string to a constant, but I'm not using it in the tests, because it can lead to false positive, I would leave it to be explicit.

@MrWolfZ
Copy link
Owner

MrWolfZ commented Feb 12, 2018

Hmm, good that I set up Travis CI to tell me I am an idiot :)

The reason I didn't use a variable before in the action types is because it messes with the type inference for actions. The TYPE property must be a string literal. Therefore, I sadly have to ask you to revert ad371d7 and d9b7918.

@lucax88x
Copy link
Contributor Author

@MrWolfZ Can you review it? we need it as this is currently breaking our tests :(

@MrWolfZ
Copy link
Owner

MrWolfZ commented Feb 15, 2018 via email

@MrWolfZ MrWolfZ merged commit 0a61def into MrWolfZ:develop Feb 15, 2018
@MrWolfZ
Copy link
Owner

MrWolfZ commented Feb 15, 2018

I have just released version 2.3.1 which contains this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants