regex - 正则表达式:javascript 字符串 ^(?!\\[functional\\]).+$ 文件上的负匹配器无法排除 [功能]
问题描述
在 package.json 我有 2 个脚本命令:
"test:unit": "jest --watch --testNamePattern='^(?!\\[functional\\]).+$'",
"test:functional": "jest --watch --testNamePattern='\\[functional\\]'",
复制^(?!\\[functional\\]).+$
到https://regex101.com/,它与下面的参数 1 中的测试字符串不匹配describe()
describe("[functional] live tests", () => {
当更改为([functional]).+$
时,模式匹配。\
我必须在每一端删除一对以删除.json
文件的转义符(我认为)。
这是我npm run test:unit
在项目根目录中运行时看到的内容:
// the functional test runs (not desired)
$ npm run test:unit
functions/src/classes/__tests__/Functional.test.ts:30:47 - error TS2339: Property 'submit' does not exist on type 'Element'.
30 await emailForm.evaluate(form => form.submit());
~~~~~~
RUNS ...s/__tests__/Functional.test.ts
Test Suites: 1 failed, 1 skipped, 3 passed, 4 of 5 total
Tests: 2 skipped, 16 passed, 18 total
Snapshots: 0 total
Time: 8.965s, estimated 27s
Ran all test suites with tests matching "^(?!\[functional\]).+$".
Active Filters: test name /^(?!\[functional\]).+$/
功能测试没有构建出来,它解释了语法错误,在这里并不重要。关键问题是为什么没有跳过测试。
我相信这个问题与正则表达式负匹配器有关。没有唯一匹配测试的正匹配器!
具有或嵌套在描述块中[functional]
$ npm run test:functional
Test Suites: 1 failed, 4 skipped, 1 of 5 total
Active Filters: test name /\[functional\]/
任何人都知道为什么负正则表达式模式在 期间失败npm run test:unit
?
解决方案
我没有使用正则表达式修复,而是将单元测试脚本上的标志更改为忽略,然后复制 [功能] 的匹配模式:
"test:unit": "jest --watch --testIgnorePattern='\\[functional\\]'",
"test:functional": "jest --watch --testNamePattern='\\[functional\\]'",
推荐阅读
- c++ - gdb 单步执行直到退出函数
- php - 具有多个模板的单个仪表板
- javascript - 基于兄弟字符串字段的对象键的Typescript动态类型
- sapui5 - Sap Fiori OData 嵌套展开
- angular - 如何在当前版本的 Angular 12 中替换“@angular/material”?
- flutter - 加载网站时获取所有请求
- flutter - 插件 cloud_firestore 和 firebase_auth 阻止与 android Emulator 同步
- google-bigquery - 在 BigQuery 中,有没有办法检查文本列值是否是有效的 JSON 字符串?
- java - 在 Java 中使用 FileInputStream 从文件中读取文本时出现问题
- r - * 与 .* 在 R 中使用正则表达式