开玩笑的js测试总是失败

时间:2020-10-10 07:54:03

标签: javascript jestjs

我对jest有疑问,我不明白原因。在单个测试中使用多个期望功能会使测试失败。我很困惑。

测试代码:

const REGEX_POST_LINK = /\[(club\d*?)(\|.*?)]/gm;
const TEST_STRING = "[club30602036|IGM]";

test("RegEx", () => {
    expect(REGEX_POST_LINK.test(TEST_STRING)).toBeTruthy();
    expect(REGEX_POST_LINK.test(TEST_STRING)).toBeTruthy();
});

结果:

$ jest
 FAIL  src/index.test.ts
  × RegEx (5 ms)

  ● RegEx

    expect(received).toBeTruthy()

    Received: false

      4 | test("RegEx", () => {
      5 |     expect(REGEX_POST_LINK.test(TEST_STRING)).toBeTruthy();
    > 6 |     expect(REGEX_POST_LINK.test(TEST_STRING)).toBeTruthy();
        |                                               ^
      7 | });
      8 | 
      9 | 

      at Object.<anonymous> (src/index.test.ts:6:47)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        2.933 s, estimated 5 s
Ran all test suites.

我会很高兴为您提供帮助,我仍在学习如何使用玩笑。

0 个答案:

没有答案