Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.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 从“返回承诺”;描述;不支持。测试必须同步定义_Javascript_Node.js_Jestjs - Fatal编程技术网

Javascript 从“返回承诺”;描述;不支持。测试必须同步定义

Javascript 从“返回承诺”;描述;不支持。测试必须同步定义,javascript,node.js,jestjs,Javascript,Node.js,Jestjs,特定的测试通过了,但我得到了这个 console.log node_modules/jest-jasmine2/build/jasmine/Env.js:502 ● Test suite failed to run Returning a Promise from "describe" is not supported. Tests must be defined synchronously. Returning

特定的测试通过了,但我得到了这个

    console.log node_modules/jest-jasmine2/build/jasmine/Env.js:502
          ● 

Test suite failed to run

            Returning a Promise from "describe" is not supported. Tests must be defined synchronously.
            Returning a value from "describe" will fail the test in a future version of Jest.

        > 4 | describe('handlers.getSemesters', async () => {
下面是完整的测试代码

describe('handlers.getSemesters', async () => {
      it('should return an array of Semesters', async () => {
        academicCalendarRequest.request = jest.fn();
        academicCalendarRequest.request.mockReturnValue([
          {
            description: 'Semester1',
          }
        ]);
        const expected = [      
          {
            description: 'Semester1',
          },
        ];

        const handlers = new Handlers();
        const actual = await handlers.getSemesters();
        expect(actual).toEqual(expected);
      });
    });
如何修复它?

更改

describe('handlers.getSemesters', async () => {

然后将异步代码放入
it
块中

it('should return an array of Semesters', async () => {
  // ...
})

En解释他为什么应该这样做会很好。文档提供了有关定义异步测试的更多信息:
it('should return an array of Semesters', async () => {
  // ...
})