RIni
RIni

Reputation: 179

how to update state in mockstore in ngrx unit testing?

I have a object defined as:

obj:{
  name:"string",
  system:"string"
}

however I am trying to update the value in mockstore as:

store.setState({
  name:"Rose",
  system:"Updated Dummy"
});
store.refreshState();
fixture.detectChanges();

but the value is not updating. How can I update the value and then verify that it has been updated as a part of unit testing?

Upvotes: 3

Views: 3432

Answers (1)

satanTime
satanTime

Reputation: 13539

store.setState updates the whole state. Therefore you need to use its feature name too to repeat the real store structure.

const featureSelector = createFeatureSelector('FEATURE_NAME_IS_HERE');

store.setState({
  FEATURE_NAME_IS_HERE: { // <- adding the feature state.
    name:"Rose",
    system:"Updated Dummy"
  },
});
store.refreshState();
fixture.detectChanges();

If you use nested reducers - then you need to nest the object to de desired child.

Upvotes: 6

Related Questions