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
Copy file name to clipboardExpand all lines: content/guides/angular/run-tests.md
+20-62Lines changed: 20 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Run Angular tests in a container
3
3
linkTitle: Run your tests
4
4
weight: 40
5
-
keywords: angular, angular, test, vitest
5
+
keywords: angular, test, jasmine
6
6
description: Learn how to run your Angular tests in a container.
7
7
8
8
---
@@ -15,10 +15,12 @@ Complete all the previous sections of this guide, starting with [Containerize An
15
15
16
16
Testing is a critical part of the development process. In this section, you'll learn how to:
17
17
18
-
- Run unit tests using Vitest inside a Docker container.
19
-
- Use Docker Compose to run tests in an isolated, reproducible environment.
18
+
- Run Jasmine unit tests using the Angular CLI inside a Docker container.
19
+
- Use Docker Compose to isolate your test environment.
20
+
- Ensure consistency between local and container-based testing.
20
21
21
-
You’ll use [Vitest](https://vitest.dev) — a blazing fast test runner designed for Vite — along with [Testing Library](https://testing-library.com/) for assertions.
22
+
23
+
`docker-angular-sample` project comes pre-configured with Jasmine, so you can get started quickly without extra setup.
22
24
23
25
---
24
26
@@ -27,64 +29,12 @@ You’ll use [Vitest](https://vitest.dev) — a blazing fast test runner designe
27
29
`docker-angular-sample` application includes a sample test file at location:
28
30
29
31
```console
30
-
$ src/App.test.tsx
31
-
```
32
-
33
-
This file uses Vitest and React Testing Library to verify the behavior of `App` component.
34
-
35
-
### Step 1: Install Vitest and React Testing Library
36
-
37
-
If you haven’t already added the necessary testing tools, install them by running:
Then, update the scripts section of your `package.json` file to include the following:
35
+
This test uses Jasmine to validate the AppComponent logic.
44
36
45
-
```json
46
-
"scripts": {
47
-
"test": "vitest run"
48
-
}
49
-
```
50
-
51
-
---
52
-
53
-
### Step 2: Configure Vitest
54
-
55
-
Update `vitest.config.ts` file in your project root with the following configuration:
56
-
57
-
```ts {hl_lines="14-18",linenos=true}
58
-
/// <referencetypes="vitest" />
59
-
60
-
import { defineConfig } from"vite";
61
-
importangularfrom"@vitejs/plugin-angular";
62
-
63
-
exportdefaultdefineConfig({
64
-
base: "/",
65
-
plugins: [angular()],
66
-
server: {
67
-
host: true,
68
-
port: 5173,
69
-
strictPort: true,
70
-
},
71
-
test: {
72
-
environment: "jsdom",
73
-
setupFiles: "./src/setupTests.ts",
74
-
globals: true,
75
-
},
76
-
});
77
-
```
78
-
79
-
> [!NOTE]
80
-
> The `test` options in `vitest.config.ts` are essential for reliable testing inside Docker:
81
-
> -`environment: "jsdom"` simulates a browser-like environment for rendering and DOM interactions.
82
-
> -`setupFiles: "./src/setupTests.ts"` loads global configuration or mocks before each test file (optional but recommended).
83
-
> -`globals: true` enables global test functions like `describe`, `it`, and `expect` without importing them.
84
-
>
85
-
> For more details, see the official [Vitest configuration docs](https://vitest.dev/config/).
86
-
87
-
### Step 3: Update compose.yaml
37
+
### Step 1: Update compose.yaml
88
38
89
39
Add a new service named `angular-test` to your `compose.yaml` file. This service allows you to run your test suite in an isolated containerized environment.
90
40
@@ -133,7 +83,7 @@ After completing the previous steps, your project directory should contain the f
133
83
│ └── README.Docker.md
134
84
```
135
85
136
-
### Step 4: Run the tests
86
+
### Step 2: Run the tests
137
87
138
88
To execute your test suite inside the container, run the following command from your project root:
139
89
@@ -146,6 +96,15 @@ This command will:
146
96
- Execute the `npm run test` script using the same environment as development.
147
97
- Automatically remove the container after the tests complete [`docker compose run --rm`](/engine/reference/commandline/compose_run) command.
148
98
99
+
The output should look something like this:
100
+
101
+
```text
102
+
Test Suites: 1 passed, 1 total
103
+
Tests: 3 passed, 3 total
104
+
Snapshots: 0 total
105
+
Time: 1.529 s
106
+
```
107
+
149
108
> [!NOTE]
150
109
> For more information about Compose commands, see the [Compose CLI
0 commit comments