You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Finally you need to modify the `package.json` to configure the reporter. Reporters are plugins that provide new export formats for test results to test runners. To do so edit `package.json` and add these lines after the `scripts` property.
94
-
95
-
```JSON
96
-
"jest-junit": {
97
-
"output": "temp/test/junit/junit.xml",
98
-
"usePathForSuiteName": "true"
99
-
}
100
-
```
101
97
#### Writing a unit test
102
98
To write your first unit test, create a new file `src/webparts/webPartName/tests/webPartName.spec.ts` and add the following content:
103
99
```TS
104
-
/// <referencetypes="mocha" />
105
-
import {assert, expect} from'chai';
100
+
import'jest'
106
101
107
102
describe("webPartName", () => {
108
-
it("should do something", () => {
109
-
assert.ok(true, 'should be true');
110
-
});
111
-
it("should add numbers Sync fluent", () => {
112
-
const result:number=1+3;
113
-
expect(result).to.eq(4); // fluent API
103
+
test("should add numbers Sync fluent", () => {
104
+
const result =1+3;
105
+
expect(result).toBe(4); // fluent API
114
106
});
115
107
});
116
108
```
117
109
> [!NOTE]
118
-
> You can learn more about writing unit tests using Jest and Chai [here](https://jestjs.io/docs/en/getting-started.html).
110
+
> You can learn more about writing unit tests using Jest [here](https://jestjs.io/docs/en/getting-started.html). You can learn more about testing react applications with Jest and Enzyme [here](https://jestjs.io/docs/en/tutorial-react) (you can ignore the setup part).
119
111
120
112
### Importing test results
121
-
In order to get test results information attached with the build results, you need to import these test results from the test runner into Azure DevOps. To do so, add a new `Publish Test Results` task. Set the `Test results files` field to `temp/test/junit/junit.xml` and the `Search folder` to `$(Build.SourcesDirectory)`.
113
+
In order to get test results information attached with the build results, you need to import these test results from the test runner into Azure DevOps. To do so, add a new `Publish Test Results` task. Set the `Test results files` field to `**/junit.xml` and the `Search folder` to `$(Build.SourcesDirectory)`.
122
114

123
115
124
116
### Importing code coverage information
125
117
126
-
In order to get code coverage reported with the build status you need to add a task to import that information. To configure the code coverage information, add the `publish code coverage results` tasks. Make sure you set the tool to `Cobertura`, `Summary files` to `$(Build.SourcesDirectory)/temp/test/cobertura-coverage.xml` and `Report Directory` to `$(Build.SourcesDirectory)/temp/test`.
118
+
In order to get code coverage reported with the build status you need to add a task to import that information. To configure the code coverage information, add the `publish code coverage results` tasks. Make sure you set the tool to `Cobertura`, `Summary files` to `$(Build.SourcesDirectory)/**/*-coverage.xml`.
0 commit comments