【问题标题】:Jest test runner fails on certain characters in test stringJest 测试运行器在测试字符串中的某些字符上失败
【发布时间】:2021-12-24 23:19:12
【问题描述】:

假设我写了一个 Jest 测试用例:

test('encode bar', () => {
   let foo = encodeBar();
   expect(foo).toEqual("bar");
});

然后运行为:

node node_modules/.bin/jest --no-coverage -t "encode bar"

效果很好。

但是,如果我在测试用例字符串中添加一个“+”号:

test('encode + bar', () => {
   let foo = encodeBar();
   expect(foo).toEqual("bar");
});

然后运行为:

node node_modules/.bin/jest --no-coverage -t "encode + bar"

Jest 将无法运行测试。 这在某处有记录/可配置吗?

【问题讨论】:

  • 我不熟悉 Jest 来写一个实际的答案,但是这部分文档有帮助吗? regex for test files

标签: javascript typescript jestjs


【解决方案1】:

-t (--testNamePattern) 需要正则表达式,使用反斜杠转义 +-t "encode \+ bar"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 2018-05-24
    • 2012-04-25
    相关资源
    最近更新 更多