Redux saga 测试 select 效果

Redux saga test select effect

如何测试select效果?我的传奇取决于 select 的结果,但每次我只是从传奇中获得 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。请问如何将数据传递到默认状态?有更好的方法吗?

试试这个方法

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

});