Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7a64a6b

Browse files
test: add karma tests (testing-library#229)
1 parent ba8fc76 commit 7a64a6b

File tree

22 files changed

+383
-3
lines changed

22 files changed

+383
-3
lines changed

‎.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: build
2626
run: npm run build -- --skip-nx-cache
2727
- name: test
28-
run: npm run test -- --ci --code-coverage
28+
run: npm run test
2929
- name: Release
3030
if: github.repository == 'testing-library/angular-testing-library' && github.ref == 'refs/heads/main'
3131
run: npx semantic-release

‎angular.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,93 @@
9494
}
9595
}
9696
},
97+
"example-app-karma": {
98+
"projectType": "application",
99+
"root": "apps/example-app-karma",
100+
"sourceRoot": "apps/example-app-karma/src",
101+
"prefix": "app",
102+
"schematics": {},
103+
"architect": {
104+
"build": {
105+
"builder": "@angular-devkit/build-angular:browser",
106+
"options": {
107+
"outputPath": "dist/apps/example-app-karma",
108+
"index": "apps/example-app-karma/src/index.html",
109+
"main": "apps/example-app-karma/src/main.ts",
110+
"polyfills": "apps/example-app-karma/src/polyfills.ts",
111+
"tsConfig": "apps/example-app-karma/tsconfig.app.json",
112+
"assets": ["apps/example-app-karma/src/favicon.ico", "apps/example-app-karma/src/assets"],
113+
"styles": [],
114+
"scripts": [],
115+
"vendorChunk": true,
116+
"extractLicenses": false,
117+
"buildOptimizer": false,
118+
"sourceMap": true,
119+
"optimization": false,
120+
"namedChunks": true
121+
},
122+
"configurations": {
123+
"production": {
124+
"budgets": [
125+
{
126+
"type": "anyComponentStyle",
127+
"maximumWarning": "6kb"
128+
}
129+
],
130+
"fileReplacements": [
131+
{
132+
"replace": "apps/example-app-karma/src/environments/environment.ts",
133+
"with": "apps/example-app-karma/src/environments/environment.prod.ts"
134+
}
135+
],
136+
"optimization": true,
137+
"outputHashing": "all",
138+
"sourceMap": false,
139+
"namedChunks": false,
140+
"extractLicenses": true,
141+
"vendorChunk": false,
142+
"buildOptimizer": true
143+
}
144+
},
145+
"outputs": ["{options.outputPath}"]
146+
},
147+
"serve": {
148+
"builder": "@angular-devkit/build-angular:dev-server",
149+
"options": {
150+
"browserTarget": "example-app-karma:build"
151+
},
152+
"configurations": {
153+
"production": {
154+
"browserTarget": "example-app-karma:build:production"
155+
}
156+
}
157+
},
158+
"lint": {
159+
"builder": "@nrwl/linter:eslint",
160+
"options": {
161+
"lintFilePatterns": [
162+
"apps/example-app-karma/**/*.ts",
163+
"apps/example-app-karma/**/*.html",
164+
"apps/example-app-karma/src/**/*.html",
165+
"apps/example-app-karma/src/**/*.html",
166+
"apps/example-app-karma/src/**/*.html"
167+
]
168+
}
169+
},
170+
"test": {
171+
"builder": "@angular-devkit/build-angular:karma",
172+
"options": {
173+
"main": "apps/example-app-karma/src/test.ts",
174+
"tsConfig": "apps/example-app-karma/tsconfig.spec.json",
175+
"polyfills": "apps/example-app-karma/src/polyfills.ts",
176+
"karmaConfig": "apps/example-app-karma/karma.conf.js",
177+
"styles": [],
178+
"scripts": [],
179+
"assets": []
180+
}
181+
}
182+
}
183+
},
97184
"testing-library": {
98185
"root": "projects/testing-library",
99186
"sourceRoot": "projects/testing-library/src",

‎apps/example-app-karma/.browserslistrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
2+
# For additional information regarding the format and rule options, please see:
3+
# https://github.com/browserslist/browserslist#queries
4+
5+
# For the full list of supported browsers by the Angular framework, please see:
6+
# https://angular.io/guide/browser-support
7+
8+
# You can see what browsers were selected by your queries by running:
9+
# npx browserslist
10+
11+
last 1 Chrome version
12+
last 1 Firefox version
13+
last 2 Edge major versions
14+
last 2 Safari major versions
15+
last 2 iOS major versions
16+
Firefox ESR
17+
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.

‎apps/example-app-karma/.eslintrc.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"extends": "../../.eslintrc.json",
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts"],
7+
"extends": ["plugin:@nrwl/nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
8+
"parserOptions": {
9+
"project": ["apps/example-app-karma/tsconfig.*?.json"]
10+
},
11+
"rules": {
12+
"@angular-eslint/directive-selector": [
13+
"error",
14+
{
15+
"type": "attribute",
16+
"prefix": "app",
17+
"style": "camelCase"
18+
}
19+
],
20+
"@angular-eslint/component-selector": [
21+
"error",
22+
{
23+
"type": "element",
24+
"prefix": "app",
25+
"style": "kebab-case"
26+
}
27+
]
28+
}
29+
},
30+
{
31+
"files": ["*.html"],
32+
"extends": ["plugin:@nrwl/nx/angular-template"],
33+
"rules": {}
34+
}
35+
]
36+
}

‎apps/example-app-karma/karma.conf.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
module.exports = function (config) {
4+
try {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-chrome-launcher'),
11+
require('@angular-devkit/build-angular/plugins/karma'),
12+
],
13+
client: {
14+
jasmine: {
15+
// you can add configuration options for Jasmine here
16+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
17+
// for example, you can disable the random execution with `random: false`
18+
// or set a specific seed with `seed: 4321`
19+
},
20+
clearContext: false, // leave Jasmine Spec Runner output visible in browser
21+
},
22+
jasmineHtmlReporter: {
23+
suppressAll: true, // removes the duplicated traces
24+
},
25+
reporters: ['progress'],
26+
port: 9876,
27+
colors: true,
28+
logLevel: config.LOG_INFO,
29+
autoWatch: true,
30+
browsers: ['ChromeHeadless'],
31+
singleRun: true,
32+
restartOnFileChange: true,
33+
});
34+
} catch (err) {
35+
console.log(err);
36+
throw err;
37+
}
38+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { BrowserModule } from '@angular/platform-browser';
2+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
3+
import { NgModule } from '@angular/core';
4+
5+
@NgModule({
6+
declarations: [],
7+
imports: [BrowserModule, BrowserAnimationsModule],
8+
})
9+
export class AppModule {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { render, screen } from '@testing-library/angular';
2+
3+
it('https://github.com/testing-library/angular-testing-library/issues/222', async () => {
4+
const { rerender } = await render(`<div>Hello {{ name}}</div>`, {
5+
componentProperties: {
6+
name: 'Sarah',
7+
},
8+
});
9+
10+
screen.getByText('Hello Sarah');
11+
rerender({ name: 'Mark' });
12+
screen.getByText('Hello Mark');
13+
});

‎apps/example-app-karma/src/assets/.gitkeep

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const environment = {
2+
production: true,
3+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This file can be replaced during build by using the `fileReplacements` array.
2+
// `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`.
3+
// The list of file replacements can be found in `angular.json`.
4+
5+
export const environment = {
6+
production: false,
7+
};
8+
9+
/*
10+
* In development mode, to ignore zone related error stack frames such as
11+
* `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can
12+
* import the following file, but please comment it out in production mode
13+
* because it will have performance impact when throw error
14+
*/
15+
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /