【问题标题】:Jasmine Expect toMatch and ParenthesesJasmine 期望匹配和括号
【发布时间】:2014-11-06 00:46:45
【问题描述】:

我注意到,当我使用 toMatch 制定 Jasmine Expect 并且匹配的字符串包含 ( 时,它将失败。有没有其他人注意到这一点?如果有,你做了什么?

例子

当它应该返回“True”时失败或返回“False”

expect("test (test) with other stuff").toMatch("test (test)");

这传递并返回“True”

expect("test %test% with other stuff").toMatch("test %test%");

【问题讨论】:

    标签: regex angularjs unit-testing jasmine protractor


    【解决方案1】:

    toMatch() 用于正则表达式匹配。括号在正则表达式中具有特殊含义(它们用于捕获/保存组),如果您希望它们被视为普通括号,则需要对其进行转义:

    expect("test (test) with other stuff").toMatch("test \(test\)");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2011-10-01
      相关资源
      最近更新 更多