Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何测试saga文件(使用jest文件)中生成器函数中的屈服延迟(某些延迟)?_Javascript_Jestjs_Redux Saga_Redux Saga Test Plan - Fatal编程技术网

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