|
1 | 1 | ---
|
2 | 2 | title: "Unit testing JavaScript and TypeScript"
|
3 | 3 | description: Visual Studio provides support unit testing JavaScript and TypeScript code using the Node.js Tools for Visual Studio
|
4 |
| -ms.date: "06/06/2018" |
| 4 | +ms.date: "07/06/2020" |
5 | 5 | ms.topic: "how-to"
|
6 | 6 | ms.devlang: javascript
|
7 | 7 | author: "mikejo5000"
|
@@ -72,26 +72,32 @@ After opening Test Explorer (choose **Test** > **Windows** > **Test Explorer**),
|
72 | 72 | 
|
73 | 73 |
|
74 | 74 | > [!NOTE]
|
75 |
| -> Do not use the `outdir` or `outfile` option in *tsconfig.json*, because Test Explorer won't be able to find your unit tests in TypeScript files. |
| 75 | +> For TypeScript, do not use the `outdir` or `outfile` option in *tsconfig.json*, because Test Explorer won't be able to find your unit tests. |
76 | 76 |
|
77 | 77 | ## Run tests
|
78 | 78 |
|
79 |
| -You can run tests in Visual Studio 2017 or from the command line. |
| 79 | +You can run tests in Visual Studio or from the command line. |
80 | 80 |
|
81 |
| -### Run tests in Visual Studio 2017 |
| 81 | +### Run tests in Visual Studio |
82 | 82 |
|
| 83 | +::: moniker range=">=vs-2019" |
| 84 | +You can run the tests by clicking the **Run All** link in Test Explorer. Or, you can run tests by selecting one or more tests or groups, right-clicking, and selecting **Run** from the shortcut menu. Tests run in the background, and Test Explorer automatically updates and shows the results. Furthermore, you can also debug selected tests by right-clicking and selecting **Debug**. |
| 85 | +::: moniker-end |
| 86 | +::: moniker range="vs-2017" |
83 | 87 | You can run the tests by clicking the **Run All** link in Test Explorer. Or, you can run tests by selecting one or more tests or groups, right-clicking, and selecting **Run Selected Tests** from the shortcut menu. Tests run in the background, and Test Explorer automatically updates and shows the results. Furthermore, you can also debug selected tests by selecting **Debug Selected Tests**.
|
| 88 | +::: moniker-end |
84 | 89 |
|
85 |
| -> [!Warning] |
86 |
| -> Debugging unit tests using Node 8+ currently only works for JavaScript test files, |
87 |
| -> TypeScript test files will fail to hit breakpoints. As a workaround use the `debugger` keyword. |
| 90 | +For TypeScript, unit tests are run against the generated JavaScript code. |
| 91 | + |
| 92 | +> [!NOTE] |
| 93 | +> In most TypeScript scenarios, you can debug a unit test by setting a breakpoint in TypeScript code, right-clicking a test in Test Explorer, and choosing **Debug**. In more complex scenarios, such as some scenarios that use source maps, you may have difficulty hitting breakpoints in TypeScript code. As a workaround, try using the `debugger` keyword. |
88 | 94 |
|
89 | 95 | > [!NOTE]
|
90 | 96 | > We don't currently support profiling tests, or code coverage.
|
91 | 97 |
|
92 | 98 | ### Run tests from the command line
|
93 | 99 |
|
94 |
| -You can run the tests from the [Developer Command Prompt](/dotnet/framework/tools/developer-command-prompt-for-vs) for Visual Studio 2017 using the following command: |
| 100 | +You can run the tests from the [Developer Command Prompt](/dotnet/framework/tools/developer-command-prompt-for-vs) for Visual Studio using the following command: |
95 | 101 |
|
96 | 102 | ```
|
97 | 103 | vstest.console.exe <path to project file>\NodejsConsoleApp23.njsproj /TestAdapterPath:<VisualStudioFolder>\Common7\IDE\Extensions\Microsoft\NodeJsTools\TestAdapter
|
|
0 commit comments