gpt4 book ai didi

angular - 如何在 StoryBook 和 Angular 测试中设置 NGRX Store 的状态?

转载 作者:行者123 更新时间:2023-12-05 02:46:53 24 4
gpt4 key购买 nike

有谁知道如何将 StoryBook 和 Angular 与 NGRX 商店一起使用或有链接吗?

我已经按照 StoryBook 教程进行操作,但仍然无法弄清楚如何将 StoryBook 与 NGRX Store 一起使用。我可以很好地使用 StoryBook 和 Angular Dumb Components。我需要能够为我的嵌套组件的故事设置 NGRX 存储状态。

例如。在我的 SmartComponent 中,我有:

this.accountDebtor$ = this.coreStore.select( coreSelector.selectAccountDebtorState );

故事中我有:

export const LoadedAccountPanel = (args) => ({
component: AccountComponent,
props: args,
});
LoadedAccountPanel.args = {
panelData: {},
accountDebtor$: <-- How do I set the State so this gets set using the store ???,
};

最佳答案

正如 Đorđe Petrović 评论的那样,您可以使用 provideMockStore 来实现这一点。

这是一个例子:

import { provideMockStore } from '@ngrx/store/testing';


// your desired data
const example_data = {
foo: bar,
};

// the state for the mockStore
const initialState = {
state_key: example_data
};


export default {
title: 'YourComponent',
component: YourComponent,
decorators: [
moduleMetadata({
providers: [
provideMockStore({ initialState })
]
})
]
}

关于angular - 如何在 StoryBook 和 Angular 测试中设置 NGRX Store 的状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65277875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com