填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

调试测试代码

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 thesample appsample app.

要了解本测试指南中提到的这些测试特性,请参阅测试测试

For the tests features in the testing guides, seeteststests.

在浏览器中调试这些测试规约的方式与调试应用时相同。

Debug specs in the browser in the same way that you debug an application.

  1. 打开 Karma 的浏览器窗口。如果需要帮助,请参阅“设置测试”

    Reveal the Karma browser window. See Set up testing if you need help with this step.

  2. 单击 DEBUG 按钮;它会打开一个新的浏览器选项卡并重新运行测试。

    Click the DEBUG button; it opens a new browser tab and re-runs the tests.

  3. 打开浏览器的 “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).

  4. 选择 “sources” 页。

    Pick the "sources" section.

  5. 打开 1st.spec.ts 测试文件(Control/Command-P,然后开始输入该文件的名字)。

    Open the 1st.spec.ts test file (Control/Command-P, then start typing the name of the file).

  6. 在测试中设置一个断点。

    Set a breakpoint in the test.

  7. 刷新浏览器,它会在这个断点处停下来。

    Refresh the browser, and it stops at the breakpoint.