javascript - 不支持从 "describe"返回 Promise。测试必须同步定义

标签 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 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 () => {

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

然后将异步代码放入it block

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

关于javascript - 不支持从 "describe"返回 Promise。测试必须同步定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56640062/

相关文章:

javascript - 使用 Dojo 禁用 li

javascript - Node.js 文档未定义

javascript - 在 ubuntu windows 10 中使用 NPM 和 zsh shell

git - 如何运行 git pre-commit Hook 以强制暂存文件的测试覆盖率不会降低?

javascript - 如何使用 JavaScript 每秒向右移动 10 个像素并向下移动 10 个像素

javascript - 使用 Jquery,如何更改所单击对象的 css?

JavaScript - 从脚本中将值写入 html 表单

node.js - 使用 sockjs 的 channel (node.js、socket.io)

reactjs - 使用 React 和 Typescript 开 Jest 手动模拟 : mock an ES6 class dependency

reactjs - 如何传递使用 Enzyme.js 渲染的组件的 props?