【问题标题】:Redux saga test select effectRedux saga 测试选择效果
【发布时间】:2017-09-17 00:09:33
【问题描述】:

如何测试选择效果?我的传奇取决于选择的结果,但每次我只是从传奇中得到undefined。

这是我尝试过的:

在我的传奇中:

function* loadData() {
    const foo = yield select((state) => {
        return state.foo.value;
    });

    console.log('foo is :', foo);
}

在测试中:

test.only('Data saga', t => {

    const generator = loadData();
    console.log(generator.next({foo: 'blah'}).value);
    console.log(generator.next());

});

但结果是foo is : undefined。请问如何将数据传递到默认状态?有更好的方法吗?

【问题讨论】:

  • 不应该像const generator = ...; generator.next(); /*<- this is select effect descriptor*/ generator.next('bar'); /*<- this is you interpretator runnig select effect*/吗?
  • 这是正确的!你能把这个作为答案发布吗?谢谢

标签: reactjs redux react-redux redux-saga saga


【解决方案1】:

试试这个方法

test.only('Data saga', t => {

    const iterator = loadData();

    const selectFooValue = iterator.next(); // <-- this is effect descriptor

    // here you assert about selectFooValue

    const nextStep = iterator.next('bar'); // <-- this how you "running" select effect  

    // here you assert about nextStep

});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 2018-06-10
    相关资源
    最近更新 更多