You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jest测试失败:JS函数独立运行正常但测试返回Undefined求助

Jest测试返回Undefined,但函数独立运行正常

我编写了一个JavaScript函数,该函数独立运行时能正常生成预期的哈希字符串,但通过Jest测试时失败,返回值为undefined而非预期的哈希字符串。

测试报错信息如下:

FAIL  node/FileParseHashChallenge.test.js
  ● FileParseHashChallenge

    expect(received).toBe(expected) // Object.is equality

    Expected: "0bX78Xa3X9eXe8Xf9Xc4X9bX60X09X00X38XbaX9xXfiXmcX"
    Received: undefined

       7 |
       8 | test('FileParseHashChallenge', async () => {
    >  9 |   expect(await FileParseHashChallenge()).toBe('0bX78Xa3X9eXe8Xf9Xc4X9bX60X09X00X38XbaX9xXfiXmcX')
         |

执行npm test的结果:

> npm test

Test Suites: 1 failed, 3 passed, 4 total
Tests:       1 failed, 6 passed, 7 total
Snapshots:   0 total
Time:        0.736 s, estimated 1 s

我希望所有测试能够通过,恳请各位提供帮助!


内容的提问来源于stack exchange,提问作者Bevo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 14:45:56