调试测试代码
Debugging tests
如果你的测试没能如预期般工作,可以在浏览器中查看和调试它们。
If your tests aren't working as you expect them to, you can inspect and debug them in the browser.
对于测试指南中所讲的范例应用,参阅
For the sample app that the testing guides describe, see the
要了解本测试指南中提到的这些测试特性,请参阅
For the tests features in the testing guides, see
在浏览器中调试这些测试规约的方式与调试应用时相同。
Debug specs in the browser in the same way that you debug an application.
打开 Karma 的浏览器窗口。如果需要帮助,请参阅“设置测试”。
Reveal the Karma browser window. See Set up testing if you need help with this step.
单击 DEBUG 按钮;它会打开一个新的浏览器选项卡并重新运行测试。
Click the DEBUG button; it opens a new browser tab and re-runs the tests.
打开浏览器的 “Developer Tools”(Windows 上的
Ctrl-Shift-I
; macOS 上的Command-Option-I
Open the browser's “Developer Tools” (
Ctrl-Shift-I
on Windows;Command-Option-I
in macOS).选择 “sources” 页。
Pick the "sources" section.
打开
1st.spec.ts
测试文件(Control/Command-P,然后开始输入该文件的名字)。Open the
1st.spec.ts
test file (Control/Command-P, then start typing the name of the file).在测试中设置一个断点。
Set a breakpoint in the test.
刷新浏览器,它会在这个断点处停下来。
Refresh the browser, and it stops at the breakpoint.