填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫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.