-
Notifications
You must be signed in to change notification settings - Fork 405
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
🚀[FEATURE]: Mock state #1676
Comments
There are a few feature requests for mocking all without proper solution unfortunatelly. |
Hey, I apologize for the long response. The Reading through your issue I ain't sure what alternative you're looking for since If you've got routing and feature states in the storybook then a good alternative is to listen to the class StoreUpdater {
constructor(actions$: Actions, store: Store) {
actions$
.pipe(ofActionDispatched(UpdateState))
.subscribe((ctx: ActionContext<UpdateState>) => {
const addedStates = ctx.action.addedStates;
const mockedAddedStates = Object.keys(addedStates).reduce(
(accumulator, key) => {
// The `key` is a feature state name, e.g. `router`.
accumulator[key] = getMockForState(key);
return accumulator;
},
{}
);
store.reset({ ...store.snapshot(), ...mockedAddedStates });
});
}
} I'm closing this issue due to the fact that:
Thanks again
|
Relevant Package
This feature request is for @ngxs/testing @ngxs/storeDescription
A clear and concise description of the problem or missing capability...Mocking state
Describe the problem you are trying to solve
Please describe the problem. If possible please substantiate it with the use cases you want to address.We are using Storybook for component driven development (CDD). Ngxs is great to abstract our business logic from the presentation, but there is no capability to properly mock the store values when testing different states of components. Writing a plugin to log and omit action handling does the job on the outputs, but there is no such solution for the inputs.
This would make Ngxs+Storybook a killer tool for CDD.
Describe the solution you'd like
If you have a solution in mind, please describe it.Ability to mock the NgxsStore to provide example data for testing.
Describe alternatives you've considered
Have you considered any alternative solutions or workarounds?I tried acquiring and exposing a global injector to get reference to the store and dispatch an UpdateState action or call the store.reset funciton. Tried using the ngxs/testing plugin, which is outdated for Angular 10 and provided only a TestBed which was not used from the Storybook module itself.
I do realize this is a cross issue of ngxs/storybook. Curious, if any of you have a solution already used for achieving such result.
The text was updated successfully, but these errors were encountered: