Javascript 如何测试saga文件(使用jest文件)中生成器函数中的屈服延迟(某些延迟)?
在传奇档案中。生成器函数如下所示:Javascript 如何测试saga文件(使用jest文件)中生成器函数中的屈服延迟(某些延迟)?,javascript,jestjs,redux-saga,redux-saga-test-plan,Javascript,Jestjs,Redux Saga,Redux Saga Test Plan,在传奇档案中。生成器函数如下所示: function* handleCall(){ yield delay(1000); yield put(act.call()); } 我想在文档后面的test.js文件中测试延迟(1000)。我们可以使用testSaga函数创建一个模拟saga,供您断言其效果 例如 saga.ts: import { delay, put } from 'redux-saga/effects'; import * as act from './actionCr
function* handleCall(){
yield delay(1000);
yield put(act.call());
}
我想在文档后面的test.js文件中测试延迟(1000)。我们可以使用testSaga
函数创建一个模拟saga,供您断言其效果
例如
saga.ts
:
import { delay, put } from 'redux-saga/effects';
import * as act from './actionCreators';
export function* handleCall() {
yield delay(1000);
yield put(act.call());
}
export function call() {
return {
type: 'HANDLE_CALL',
};
}
import { testSaga } from 'redux-saga-test-plan';
import { handleCall } from './saga';
import * as act from './actionCreators';
describe('63494870', () => {
it('should pass', () => {
testSaga(handleCall).next().delay(1000).next().put(act.call()).next().isDone();
});
});
actionCreators.ts
:
import { delay, put } from 'redux-saga/effects';
import * as act from './actionCreators';
export function* handleCall() {
yield delay(1000);
yield put(act.call());
}
export function call() {
return {
type: 'HANDLE_CALL',
};
}
import { testSaga } from 'redux-saga-test-plan';
import { handleCall } from './saga';
import * as act from './actionCreators';
describe('63494870', () => {
it('should pass', () => {
testSaga(handleCall).next().delay(1000).next().put(act.call()).next().isDone();
});
});
saga.test.ts
:
import { delay, put } from 'redux-saga/effects';
import * as act from './actionCreators';
export function* handleCall() {
yield delay(1000);
yield put(act.call());
}
export function call() {
return {
type: 'HANDLE_CALL',
};
}
import { testSaga } from 'redux-saga-test-plan';
import { handleCall } from './saga';
import * as act from './actionCreators';
describe('63494870', () => {
it('should pass', () => {
testSaga(handleCall).next().delay(1000).next().put(act.call()).next().isDone();
});
});
测试结果:
PASS src/stackoverflow/63494870/saga.test.ts
63494870
✓ should pass (3 ms)
-------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
actionCreators.ts | 100 | 100 | 100 | 100 |
saga.ts | 100 | 100 | 100 | 100 |
-------------------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 3.689 s
跟踪文档。我们可以使用testSaga
函数创建一个模拟saga,供您断言其效果
例如
saga.ts
:
import { delay, put } from 'redux-saga/effects';
import * as act from './actionCreators';
export function* handleCall() {
yield delay(1000);
yield put(act.call());
}
export function call() {
return {
type: 'HANDLE_CALL',
};
}
import { testSaga } from 'redux-saga-test-plan';
import { handleCall } from './saga';
import * as act from './actionCreators';
describe('63494870', () => {
it('should pass', () => {
testSaga(handleCall).next().delay(1000).next().put(act.call()).next().isDone();
});
});
actionCreators.ts
:
import { delay, put } from 'redux-saga/effects';
import * as act from './actionCreators';
export function* handleCall() {
yield delay(1000);
yield put(act.call());
}
export function call() {
return {
type: 'HANDLE_CALL',
};
}
import { testSaga } from 'redux-saga-test-plan';
import { handleCall } from './saga';
import * as act from './actionCreators';
describe('63494870', () => {
it('should pass', () => {
testSaga(handleCall).next().delay(1000).next().put(act.call()).next().isDone();
});
});
saga.test.ts
:
import { delay, put } from 'redux-saga/effects';
import * as act from './actionCreators';
export function* handleCall() {
yield delay(1000);
yield put(act.call());
}
export function call() {
return {
type: 'HANDLE_CALL',
};
}
import { testSaga } from 'redux-saga-test-plan';
import { handleCall } from './saga';
import * as act from './actionCreators';
describe('63494870', () => {
it('should pass', () => {
testSaga(handleCall).next().delay(1000).next().put(act.call()).next().isDone();
});
});
测试结果:
PASS src/stackoverflow/63494870/saga.test.ts
63494870
✓ should pass (3 ms)
-------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
actionCreators.ts | 100 | 100 | 100 | 100 |
saga.ts | 100 | 100 | 100 | 100 |
-------------------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 3.689 s