Skip to content

Commit 91597cb

Browse files
committed
init ngx-testing-library
0 parents  commit 91597cb

40 files changed

+14751
-0
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Editor configuration, see http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
max_line_length = off
13+
trim_trailing_whitespace = false

.gitignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
8+
# dependencies
9+
/node_modules
10+
11+
# IDEs and editors
12+
/.idea
13+
.project
14+
.classpath
15+
.c9/
16+
*.launch
17+
.settings/
18+
*.sublime-workspace
19+
20+
# IDE - VSCode
21+
.vscode/*
22+
!.vscode/settings.json
23+
!.vscode/tasks.json
24+
!.vscode/launch.json
25+
!.vscode/extensions.json
26+
27+
# misc
28+
/.sass-cache
29+
/connect.lock
30+
/coverage
31+
/libpeerconnection.log
32+
npm-debug.log
33+
yarn-error.log
34+
testem.log
35+
/typings
36+
37+
# System Files
38+
.DS_Store
39+
Thumbs.db

README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# NgxTestingLibraryApp
2+
3+
Test your Angular components with the [dom-testing-library](https://github.com/kentcdodds/dom-testing-library).
4+
5+
Go from
6+
7+
```ts
8+
import { TestBed, async } from '@angular/core/testing';
9+
import { AppComponent } from './app.component';
10+
11+
describe('AppComponent', () => {
12+
beforeEach(async(() => {
13+
TestBed.configureTestingModule({
14+
declarations: [AppComponent],
15+
}).compileComponents();
16+
}));
17+
18+
it(`should have as title 'my-awesome-app'`, async(() => {
19+
const fixture = TestBed.createComponent(AppComponent);
20+
const app = fixture.debugElement.componentInstance;
21+
expect(app.title).toEqual('my-awesome-app');
22+
}));
23+
24+
it('should render title in a h1 tag', async(() => {
25+
const fixture = TestBed.createComponent(AppComponent);
26+
fixture.detectChanges();
27+
const compiled = fixture.debugElement.nativeElement;
28+
expect(compiled.querySelector('h1').textContent).toContain('Welcome to my-awesome-app!');
29+
}));
30+
});
31+
```
32+
33+
to
34+
35+
```ts
36+
import { AppComponent } from './app.component';
37+
import { createComponent } from 'ngx-testing-library';
38+
39+
test(`should have as title 'my-awesome-app'`, async () => {
40+
const { detectChanges, getByText } = await createComponent('<app-root></app-root>', {
41+
declarations: [AppComponent],
42+
});
43+
expect(getByText('Welcome to my-awesome-app!')).toBeDefined();
44+
});
45+
46+
test(`should render title in a h1 tag`, async () => {
47+
const { container } = await createComponent('<app-root></app-root>', {
48+
declarations: [AppComponent],
49+
});
50+
expect(container.querySelector('h1').textContent).toContain('Welcome to my-awesome-app!');
51+
});
52+
```

angular.json

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"ngx-testing-library-app": {
7+
"root": "",
8+
"sourceRoot": "src",
9+
"projectType": "application",
10+
"prefix": "app",
11+
"schematics": {},
12+
"architect": {
13+
"build": {
14+
"builder": "@angular-devkit/build-angular:browser",
15+
"options": {
16+
"outputPath": "dist/ngx-testing-library-app",
17+
"index": "src/index.html",
18+
"main": "src/main.ts",
19+
"polyfills": "src/polyfills.ts",
20+
"tsConfig": "src/tsconfig.app.json",
21+
"assets": ["src/favicon.ico", "src/assets"],
22+
"styles": ["src/styles.css"],
23+
"scripts": []
24+
},
25+
"configurations": {
26+
"production": {
27+
"fileReplacements": [
28+
{
29+
"replace": "src/environments/environment.ts",
30+
"with": "src/environments/environment.prod.ts"
31+
}
32+
],
33+
"optimization": true,
34+
"outputHashing": "all",
35+
"sourceMap": false,
36+
"extractCss": true,
37+
"namedChunks": false,
38+
"aot": true,
39+
"extractLicenses": true,
40+
"vendorChunk": false,
41+
"buildOptimizer": true
42+
}
43+
}
44+
},
45+
"serve": {
46+
"builder": "@angular-devkit/build-angular:dev-server",
47+
"options": {
48+
"browserTarget": "ngx-testing-library-app:build"
49+
},
50+
"configurations": {
51+
"production": {
52+
"browserTarget": "ngx-testing-library-app:build:production"
53+
}
54+
}
55+
},
56+
"extract-i18n": {
57+
"builder": "@angular-devkit/build-angular:extract-i18n",
58+
"options": {
59+
"browserTarget": "ngx-testing-library-app:build"
60+
}
61+
},
62+
"lint": {
63+
"builder": "@angular-devkit/build-angular:tslint",
64+
"options": {
65+
"tsConfig": ["src/tsconfig.app.json", "./tsconfig.spec.json"],
66+
"exclude": ["**/node_modules/**"]
67+
}
68+
}
69+
}
70+
},
71+
"ngx-testing-library": {
72+
"root": "projects/ngx-testing-library",
73+
"sourceRoot": "projects/ngx-testing-library/src",
74+
"projectType": "library",
75+
"prefix": "lib",
76+
"architect": {
77+
"build": {
78+
"builder": "@angular-devkit/build-ng-packagr:build",
79+
"options": {
80+
"tsConfig": "projects/ngx-testing-library/tsconfig.lib.json",
81+
"project": "projects/ngx-testing-library/ng-package.json"
82+
},
83+
"configurations": {
84+
"production": {
85+
"project": "projects/ngx-testing-library/ng-package.prod.json"
86+
}
87+
}
88+
},
89+
"lint": {
90+
"builder": "@angular-devkit/build-angular:tslint",
91+
"options": {
92+
"tsConfig": ["projects/ngx-testing-library/tsconfig.lib.json", "./tsconfig.spec.json"],
93+
"exclude": ["**/node_modules/**"]
94+
}
95+
}
96+
}
97+
}
98+
},
99+
"defaultProject": "ngx-testing-library-app"
100+
}

jest.app.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const baseConfig = require('./jest.base.config');
2+
3+
module.exports = {
4+
...baseConfig,
5+
roots: ['<rootDir>/src'],
6+
modulePathIgnorePatterns: ['<rootDir>/projects'],
7+
moduleNameMapper: {
8+
'ngx-testing-library': '<rootDir>/dist/ngx-testing-library',
9+
},
10+
};

jest.base.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
preset: 'jest-preset-angular',
3+
setupTestFrameworkScriptFile: '<rootDir>/test.ts',
4+
globals: {
5+
'ts-jest': {
6+
tsConfigFile: './tsconfig.spec.json',
7+
},
8+
__TRANSFORM_HTML__: true,
9+
},
10+
};

jest.lib.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const baseConfig = require('./jest.base.config');
2+
3+
module.exports = {
4+
...baseConfig,
5+
roots: ['<rootDir>/projects'],
6+
};

0 commit comments

Comments
 (0)