gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 23:02:55 25 4
gpt4 key购买 nike

特定测试已通过,但我明白了。

    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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com