如何在 NGRX 单元测试中更新模拟商店中的状态?



>我有一个对象定义为:

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

但是我正在尝试将模拟商店中的值更新为:

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

但该值未更新。如何更新值,然后验证它是否已作为单元测试的一部分进行更新?

store.setState更新整个状态。因此,您还需要使用其功能名称来重复真实的商店结构。

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();

如果使用嵌套化简器 - 则需要将对象嵌套到 de 所需的子级。

最新更新