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

Integration testing of @Effect() observables #491

Closed
dinvlad opened this issue Oct 16, 2017 · 1 comment
Closed

Integration testing of @Effect() observables #491

dinvlad opened this issue Oct 16, 2017 · 1 comment

Comments

@dinvlad
Copy link
Contributor

dinvlad commented Oct 16, 2017

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[x] Feature request
[ ] Documentation issue or request

What is the current behavior?

One is able to unit-test individual effect observables.

Expected behavior:

We should be able to test that these observables are properly registered with the store (i.e. provide an integration test). For example, an observable may be provided and behave correctly in isolation, but a developer can forget or accidentally remove a corresponding @Effect decorator.

We should also be able to test that the decorator has been configured correctly. E.g. to test that "dispatch: false" was set.

Although we can indeed instantiate the "real" store and subscribe to its Actions, actions returned from effects in this way don't get "immediately" dispatched in a test. As a result, it is unclear how to "wait" until a particular effect "settled down" before testing whether this effect resulted in a dispatch of a new action, or whether no dispatch happened (if "dispatch: false").

If that's possible to achieve with the current implementation, could you provide an example how to?

Minimal reproduction of the problem with instructions:

https:/ngrx/platform/blob/master/example-app/app/auth/effects/auth.effects.ts

Version of affected browser(s),operating system(s), npm, node and ngrx:

any

Other information:

@dinvlad
Copy link
Contributor Author

dinvlad commented Oct 16, 2017

As a possible solution, we could expose

export const getSourceMetadata = compose(
getEffectMetadataEntries,
getSourceForInstance
);

getSourceMetadata() returns all of the necessary information to enable these tests.

Moreover, we can then get by with simple unit tests, and the integration test will consist of a single
expect(TestBed.get(EffectsClass)).toBeDefined() when TestBed imports an entire store module.

Currently, we can

import { getSourceMetadata } from '@ngrx/effects/src/effects_metadata';

but I assume that is not reliable as it's not exposed through the API?
I can submit a PR to export it through @ngrx/effects/testing.

dinvlad pushed a commit to dinvlad/platform that referenced this issue Oct 17, 2017
This PR exposes a method to get metadata supplied
through @effect() decorator.

This method is useful for when we want to test
that an effect was properly decorated/registered
in the store.

Related issue: ngrx#491
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

No branches or pull requests

1 participant