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

An approach for unit testing epics #312

Open
jchapuis opened this issue Aug 22, 2017 · 5 comments

Comments

@jchapuis
Copy link
Contributor

commented Aug 22, 2017

Since the documentation was inviting for descriptions of testing approaches, I've described the one I'm using in the following blog post: http://jonaschapuis.com/index.php/2017/08/22/marble-testing-redux-observable-epics/

I hope you will find it interesting!

@nasreddineskandrani

This comment has been minimized.

Copy link
Contributor

commented Nov 17, 2017

your actionsOfType is cool. The owner can think about adding it to the doc of lib for people that use typescript.
or a friend of mine did this to type and remove boilerplate also at the reducer level not only epic if you want to take a look: https://github.com/aminpaks/redux-typed-actions

@jayphelps

This comment has been minimized.

Copy link
Member

commented Nov 17, 2017

@jchapuis very cool! I dig your actionsOfType. I've tried to get ofType to automatically narrow the type in the past, but TS isn't yet able to infer it so I gave up. If it's useful for people to pass the narrowed type as a generic param instead of narrowing it in the next operator, we can do something like this:

class ActionsObservable<T extends Action> extends Observable<T> {
  ofType<R extends Action = T>(...key: T['type'][]): ActionsObservable<R>;
}

// which allows the same behavior as `actionsOfType` I believe:

action$.ofType<SomeNarrowAction>(someType);
@jayphelps

This comment has been minimized.

Copy link
Member

commented Nov 17, 2017

In case anyone's curious, here's some previous discussion around narrowing the action type automatically, which isn't yet supported by TS: https://stackoverflow.com/questions/46312206/narrowing-a-return-type-from-a-generic-discriminated-union-in-typescript

and the TS ticket tracking it: microsoft/TypeScript#17915

@jchapuis

This comment has been minimized.

Copy link
Contributor Author

commented Nov 21, 2017

@jayphelps great if you can integrate this narrowing version for ofType() directly! This is what I had the need for in practice, to reduce the boilerplate as much as I could. Btw. I had no idea you could formulate such type constraints as R extends Action = T

@jayphelps

This comment has been minimized.

Copy link
Member

commented Nov 21, 2017

Not sure when I’ll be able to get to it but I’ll try to remember. Feel free to PR if you have time.

jchapuis pushed a commit to jchapuis/redux-observable that referenced this issue Nov 24, 2017

jchapuis
feat(ofType): typed overload (redux-observable#312)
addition of a narrowing `ofType()` overload.
allows for behavior such as `action$.ofType<SomeNarrowAction>(someType);`

jayphelps added a commit that referenced this issue Nov 28, 2017

feat(ofType): `ofType()` TypeScript overload that permits narrowing t…
…he filtered actions type `action$.ofType<SomeNarrowAction>(someType);` (#312) (#370)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.