我的单元测试是用茉莉花编写的,而且是在打字稿中
// about.service.spec.ts
// say 4 to 5 test cases
// spec/support/jasmine.json
{
"spec_dir": "src/tests/",
"spec_files": ["**/*.spec.ts"],
"helpers": ["jasmine-helpers/**/*.ts"],
...
}
// launch.json - vscode file
{
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "Jasmine tests",
"preLaunchTask": "debuggertests",
}]
}
// tasks.json - vscode
{
"version": "2.0.0",
"tasks": [{
"label": "debuggertests",
"type": "npm",
"script": "test:unit",
"problemMatcher": []
}]
}
// package.json
// have to use jasmine-ts which is flavor over ts-node
"test:unit": "jasmine-ts JASMINE_CONFIG_PATH=spec/support/jasmine.json"
我已经使用此配置来调试vscode中的.spec.ts文件,但它没有触发调试器,而是运行所有测试并开始调试。
我在about.service.spec.ts的一个测试用例中放了一个断点但没有触发断点。有人可以帮我设置茉莉花测试的vscode调试吗?
答案 0 :(得分:3)
以下配置将调试当前的测试文件-请在VS Code中打开所需的测试文件,然后使用此配置开始调试:
{
"type": "node",
"request": "launch",
"name": "Jasmine Current File",
"program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
"args": ["${file}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
答案 1 :(得分:1)
在新的jasmine-ts版本中,您必须将jasmine.json包含在args中,如下所示:
{
"type": "node",
"request": "launch",
"name": "Jasmine Current File",
"program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
"args": ["--config=jasmine.json", "${file}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
为避免此问题:
未找到规格 在0.003秒内完成 不完整:找不到规格 随机种子60766(茉莉花--random = true --seed = 60766)