Skip to content

Commit

Permalink
init ngx-testing-library
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Jun 12, 2018
0 parents commit 91597cb
Show file tree
Hide file tree
Showing 40 changed files with 14,751 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Editor configuration, see http://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc

# dependencies
/node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings

# System Files
.DS_Store
Thumbs.db
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# NgxTestingLibraryApp

Test your Angular components with the [dom-testing-library](https://github.com/kentcdodds/dom-testing-library).

Go from

```ts
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';

describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
}).compileComponents();
}));

it(`should have as title 'my-awesome-app'`, async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('my-awesome-app');
}));

it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to my-awesome-app!');
}));
});
```

to

```ts
import { AppComponent } from './app.component';
import { createComponent } from 'ngx-testing-library';

test(`should have as title 'my-awesome-app'`, async () => {
const { detectChanges, getByText } = await createComponent('<app-root></app-root>', {
declarations: [AppComponent],
});
expect(getByText('Welcome to my-awesome-app!')).toBeDefined();
});

test(`should render title in a h1 tag`, async () => {
const { container } = await createComponent('<app-root></app-root>', {
declarations: [AppComponent],
});
expect(container.querySelector('h1').textContent).toContain('Welcome to my-awesome-app!');
});
```
100 changes: 100 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"ngx-testing-library-app": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/ngx-testing-library-app",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["src/styles.css"],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "ngx-testing-library-app:build"
},
"configurations": {
"production": {
"browserTarget": "ngx-testing-library-app:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "ngx-testing-library-app:build"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["src/tsconfig.app.json", "./tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
}
},
"ngx-testing-library": {
"root": "projects/ngx-testing-library",
"sourceRoot": "projects/ngx-testing-library/src",
"projectType": "library",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/ngx-testing-library/tsconfig.lib.json",
"project": "projects/ngx-testing-library/ng-package.json"
},
"configurations": {
"production": {
"project": "projects/ngx-testing-library/ng-package.prod.json"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["projects/ngx-testing-library/tsconfig.lib.json", "./tsconfig.spec.json"],
"exclude": ["**/node_modules/**"]
}
}
}
}
},
"defaultProject": "ngx-testing-library-app"
}
10 changes: 10 additions & 0 deletions jest.app.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const baseConfig = require('./jest.base.config');

module.exports = {
...baseConfig,
roots: ['<rootDir>/src'],
modulePathIgnorePatterns: ['<rootDir>/projects'],
moduleNameMapper: {
'ngx-testing-library': '<rootDir>/dist/ngx-testing-library',
},
};
10 changes: 10 additions & 0 deletions jest.base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
preset: 'jest-preset-angular',
setupTestFrameworkScriptFile: '<rootDir>/test.ts',
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.spec.json',
},
__TRANSFORM_HTML__: true,
},
};
6 changes: 6 additions & 0 deletions jest.lib.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const baseConfig = require('./jest.base.config');

module.exports = {
...baseConfig,
roots: ['<rootDir>/projects'],
};
Loading

0 comments on commit 91597cb

Please sign in to comment.