I followed the official documentation on testing ngxs selectors (https://ngxs.gitbook.io/ngxs/recipes/unit-testing#testing-selectors), however it doesn't cover how to unittest dynamic selectors created with createSelector
.
My normal selector just gets the state as an argument so I can easly test it by passing a prepared state and comparing the output.
@Selector()
static nachweise(state: NachweisStateModel) {
return state.nachweise;
}
//Setup state
const state = {...};
//Compare expectations
expect(NachweisState.nachweise(state)).toEqual(...);
My dynamic selector looks like this:
@Selector()
static nachweisById(id: string) {
return createSelector([NachweisState], state => {
return state.nachweise.find(nachweis => nachweis.id === id);
});
}
The only parameter it gets is the id by which it selects, but not the state. The State is automagically passed in by specifying it as the first parameter to createSelector
and I don't know how I should test this selector.
Aucun commentaire:
Enregistrer un commentaire