Skip to content

Commit

Permalink
feat: upgrade to Angular 6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Jul 28, 2018
1 parent 64e63f7 commit e6e6c26
Show file tree
Hide file tree
Showing 8 changed files with 988 additions and 1,460 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
key: *dist_key
- run:
name: release
command: cd dist/ngx-testing-library && npm run semantic-release || true
command: npm run semantic-release || true

workflows:
version: 2
Expand Down
1 change: 1 addition & 0 deletions jest.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
preset: 'jest-preset-angular',
rootDir: '../',
setupTestFrameworkScriptFile: '<rootDir>/test.ts',
testURL: 'http://localhost',
globals: {
'ts-jest': {
tsConfigFile: './tsconfig.spec.json',
Expand Down
2,236 changes: 930 additions & 1,306 deletions package-lock.json

Large diffs are not rendered by default.

58 changes: 30 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,43 @@
"git add"
]
},
"release": {
"pkgRoot": "dist/ngx-testing-library"
},
"dependencies": {
"@angular/common": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/animations": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"@angular/common": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/animations": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"rxjs": "^6.2.2",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.8",
"@angular-devkit/build-ng-packagr": "~0.6.8",
"@angular/cli": "~6.0.8",
"@angular/compiler-cli": "^6.0.3",
"@angular/language-service": "^6.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"dom-testing-library": "^3.0.0",
"@angular-devkit/build-angular": "~0.7.1",
"@angular-devkit/build-ng-packagr": "~0.7.1",
"@angular/cli": "~6.1.1",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/node": "~10.5.4",
"codelyzer": "~4.4.2",
"dom-testing-library": "^3.0.2",
"husky": "^0.14.3",
"jest": "^23.1.0",
"jest-preset-angular": "^5.2.2",
"jest": "^23.4.2",
"jest-preset-angular": "^5.2.3",
"lint-staged": "^7.2.0",
"ng-packagr": "^3.0.0-rc.2",
"prettier": "^1.13.5",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tsickle": ">=0.25.5",
"tslib": "^1.7.1",
"tslint": "~5.9.1",
"typescript": "^2.7.2",
"ng-packagr": "^3.0.6",
"prettier": "^1.13.7",
"ts-node": "~7.0.0",
"tsickle": "0.32.1",
"tslib": "^1.9.3",
"tslint": "~5.11.0",
"typescript": "^2.9.2",
"semantic-release": "^15.8.1"
}
}
6 changes: 3 additions & 3 deletions projects/ngx-testing-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
},
"homepage": "https://github.com/timdeschryver/ngx-testing-library#readme",
"peerDependencies": {
"@angular/common": "^6.0.0-rc.0 || ^6.0.0",
"@angular/core": "^6.0.0-rc.0 || ^6.0.0"
"@angular/common": "^6.1.0",
"@angular/core": "^6.1.0"
},
"dependencies": {
"dom-testing-library": "^2.5.0"
"dom-testing-library": "^3.0.2"
}
}
107 changes: 3 additions & 104 deletions projects/ngx-testing-library/src/lib/models.ts
Original file line number Diff line number Diff line change
@@ -1,113 +1,12 @@
import { Type } from '@angular/core';
import { ComponentFixture } from '@angular/core/testing';
import { getQueriesForElement, FireObject } from 'dom-testing-library';

export interface Result<T> {
export interface RenderResult extends ReturnType<typeof getQueriesForElement>, FireObject {
container: HTMLElement;
getFromTestBed: (token: any, notFoundValue?: any) => any;
debug: () => void;
getFromTestBed: (token: any, notFoundValue?: any) => any;
fixture: ComponentFixture<any>;

// Currently this isn't perfect because the typings from dom-testing-library are for TS 2.8
// dom-testing-library queroes
queryByPlaceholderText: any;
queryAllByPlaceholderText: any;
getByPlaceholderText: any;
getAllByPlaceholderText: any;
queryByText: any;
queryAllByText: any;
getByText: any;
getAllByText: any;
queryByLabelText: any;
queryAllByLabelText: any;
getByLabelText: any;
getAllByLabelText: any;
queryByAltText: any;
queryAllByAltText: any;
getByAltText: any;
getAllByAltText: any;
queryByTestId: any;
queryAllByTestId: any;
getByTestId: any;
getAllByTestId: any;
queryByTitle: any;
queryAllByTitle: any;
getByTitle: any;
getAllByTitle: any;
queryByValue: any;
queryAllByValue: any;
getByValue: any;
getAllByValue: any;

// dom-testing-library fireEvents
copy: (element: HTMLElement, options?: {}) => boolean;
cut: (element: HTMLElement, options?: {}) => boolean;
paste: (element: HTMLElement, options?: {}) => boolean;
compositionEnd: (element: HTMLElement, options?: {}) => boolean;
compositionStart: (element: HTMLElement, options?: {}) => boolean;
compositionUpdate: (element: HTMLElement, options?: {}) => boolean;
keyDown: (element: HTMLElement, options?: {}) => boolean;
keyPress: (element: HTMLElement, options?: {}) => boolean;
keyUp: (element: HTMLElement, options?: {}) => boolean;
focus: (element: HTMLElement, options?: {}) => boolean;
blur: (element: HTMLElement, options?: {}) => boolean;
change: (element: HTMLElement, options?: {}) => boolean;
input: (element: HTMLElement, options?: {}) => boolean;
invalid: (element: HTMLElement, options?: {}) => boolean;
submit: (element: HTMLElement, options?: {}) => boolean;
click: (element: HTMLElement, options?: {}) => boolean;
contextMenu: (element: HTMLElement, options?: {}) => boolean;
dblClick: (element: HTMLElement, options?: {}) => boolean;
drag: (element: HTMLElement, options?: {}) => boolean;
dragEnd: (element: HTMLElement, options?: {}) => boolean;
dragEnter: (element: HTMLElement, options?: {}) => boolean;
dragExit: (element: HTMLElement, options?: {}) => boolean;
dragLeave: (element: HTMLElement, options?: {}) => boolean;
dragOver: (element: HTMLElement, options?: {}) => boolean;
dragStart: (element: HTMLElement, options?: {}) => boolean;
drop: (element: HTMLElement, options?: {}) => boolean;
mouseDown: (element: HTMLElement, options?: {}) => boolean;
mouseEnter: (element: HTMLElement, options?: {}) => boolean;
mouseLeave: (element: HTMLElement, options?: {}) => boolean;
mouseMove: (element: HTMLElement, options?: {}) => boolean;
mouseOut: (element: HTMLElement, options?: {}) => boolean;
mouseOver: (element: HTMLElement, options?: {}) => boolean;
mouseUp: (element: HTMLElement, options?: {}) => boolean;
select: (element: HTMLElement, options?: {}) => boolean;
touchCancel: (element: HTMLElement, options?: {}) => boolean;
touchEnd: (element: HTMLElement, options?: {}) => boolean;
touchMove: (element: HTMLElement, options?: {}) => boolean;
touchStart: (element: HTMLElement, options?: {}) => boolean;
scroll: (element: HTMLElement, options?: {}) => boolean;
wheel: (element: HTMLElement, options?: {}) => boolean;
abort: (element: HTMLElement, options?: {}) => boolean;
canPlay: (element: HTMLElement, options?: {}) => boolean;
canPlayThrough: (element: HTMLElement, options?: {}) => boolean;
durationChange: (element: HTMLElement, options?: {}) => boolean;
emptied: (element: HTMLElement, options?: {}) => boolean;
encrypted: (element: HTMLElement, options?: {}) => boolean;
ended: (element: HTMLElement, options?: {}) => boolean;
loadedData: (element: HTMLElement, options?: {}) => boolean;
loadedMetadata: (element: HTMLElement, options?: {}) => boolean;
loadStart: (element: HTMLElement, options?: {}) => boolean;
pause: (element: HTMLElement, options?: {}) => boolean;
play: (element: HTMLElement, options?: {}) => boolean;
playing: (element: HTMLElement, options?: {}) => boolean;
progress: (element: HTMLElement, options?: {}) => boolean;
rateChange: (element: HTMLElement, options?: {}) => boolean;
seeked: (element: HTMLElement, options?: {}) => boolean;
seeking: (element: HTMLElement, options?: {}) => boolean;
stalled: (element: HTMLElement, options?: {}) => boolean;
suspend: (element: HTMLElement, options?: {}) => boolean;
timeUpdate: (element: HTMLElement, options?: {}) => boolean;
volumeChange: (element: HTMLElement, options?: {}) => boolean;
waiting: (element: HTMLElement, options?: {}) => boolean;
load: (element: HTMLElement, options?: {}) => boolean;
error: (element: HTMLElement, options?: {}) => boolean;
animationStart: (element: HTMLElement, options?: {}) => boolean;
animationEnd: (element: HTMLElement, options?: {}) => boolean;
animationIteration: (element: HTMLElement, options?: {}) => boolean;
transitionEnd: (element: HTMLElement, options?: {}) => boolean;
doubleClick: (element: HTMLElement, options?: {}) => boolean;
}

export interface Options {
Expand Down
36 changes: 19 additions & 17 deletions projects/ngx-testing-library/src/lib/ngx-testing-library.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { Component, NgModule, Type } from '@angular/core';
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { getQueriesForElement, prettyDOM, fireEvent } from 'dom-testing-library';
import { Component } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { getQueriesForElement, prettyDOM, fireEvent, FireFunction, FireObject } from 'dom-testing-library';

import { Options, Result, ComponentInput } from './models';
import { Options, RenderResult, ComponentInput } from './models';

@Component({ selector: 'test-component', template: '' })
class TestComponent {}

export async function createComponent<T>(template: string, options: Options): Promise<Result<T>>;
export async function createComponent<T>(component: ComponentInput<T>, options: Options): Promise<Result<T>>;
export async function createComponent<T>(template: string, options: Options): Promise<RenderResult>;
export async function createComponent<T>(component: ComponentInput<T>, options: Options): Promise<RenderResult>;
export async function createComponent<T>(
templateOrComponent: string | ComponentInput<T>,
{ detectChanges = true, declarations = [], providers = [], imports = [], schemas = [] }: Options,
): Promise<Result<T>> {
): Promise<RenderResult> {
const isTemplate = typeof templateOrComponent === 'string';
const testComponent = isTemplate ? [TestComponent] : [];

Expand All @@ -34,21 +33,24 @@ export async function createComponent<T>(
fixture.detectChanges();
}

const eventsWithChangeDetection = Object.keys(fireEvent).reduce((events, key) => {
events[key] = (element: HTMLElement, options?: {}) => {
const result = fireEvent[key](element, options);
fixture.detectChanges();
return result;
};
return events;
}, {});
const eventsWithDetectChanges = Object.keys(fireEvent).reduce(
(events, key) => {
events[key] = (element: HTMLElement, options?: {}) => {
const result = fireEvent[key](element, options);
fixture.detectChanges();
return result;
};
return events;
},
{} as FireObject,
);

return {
fixture,
container: fixture.nativeElement,
getFromTestBed: TestBed.get,
debug: () => console.log(prettyDOM(fixture.nativeElement)),
...eventsWithChangeDetection,
...eventsWithDetectChanges,
...getQueriesForElement(fixture.nativeElement),
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/__snapshots__/app.component.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`matches snapshot 1`] = `
<div
id="root0"
ng-version="6.0.4"
ng-version="6.1.0"
>
<app-root>
<div
Expand Down

0 comments on commit e6e6c26

Please sign in to comment.