Skip to content

Commit

Permalink
Merge pull request #191 from satanTime/issues/175
Browse files Browse the repository at this point in the history
feat: exclude feature to MockBuilder
  • Loading branch information
satanTime authored Sep 30, 2020
2 parents 5304733 + d839f27 commit e034dd7
Show file tree
Hide file tree
Showing 17 changed files with 1,260 additions and 749 deletions.
1,285 changes: 648 additions & 637 deletions README.md

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions e2e/a10es2015ivy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"test:jest": "jest --runInBand",
"test:jest:debug": "jest --watch",
"lint": "ng lint",
"puppeteer": "npm install puppeteer@~3.3.0 --no-save",
"postinstall": "ngcc"
"puppeteer": "npm install puppeteer@~3.3.0 --no-save"
},
"private": true,
"peerDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions e2e/a10es2015noivy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"test:jest": "jest --runInBand",
"test:jest:debug": "jest --watch",
"lint": "ng lint",
"puppeteer": "npm install puppeteer@~3.3.0 --no-save",
"postinstall": "ngcc"
"puppeteer": "npm install puppeteer@~3.3.0 --no-save"
},
"private": true,
"peerDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions e2e/a10es5ivy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"test:jest": "jest --runInBand",
"test:jest:debug": "jest --watch",
"lint": "ng lint",
"puppeteer": "npm install puppeteer@~3.3.0 --no-save",
"postinstall": "ngcc"
"puppeteer": "npm install puppeteer@~3.3.0 --no-save"
},
"private": true,
"peerDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions e2e/a10es5noivy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"test:jest": "jest --runInBand",
"test:jest:debug": "jest --watch",
"lint": "ng lint",
"puppeteer": "npm install puppeteer@~3.3.0 --no-save",
"postinstall": "ngcc"
"puppeteer": "npm install puppeteer@~3.3.0 --no-save"
},
"private": true,
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion e2e/a9es2015ivy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ngcc && npm run test:jasmine -- --progress=false && npm run test:jest",
"test": "npm run test:jasmine -- --progress=false && npm run test:jest",
"test:jasmine": "ng test",
"test:jasmine:debug": "ng test -- --watch --browsers Chrome",
"test:jest": "jest --runInBand",
Expand Down
2 changes: 1 addition & 1 deletion e2e/a9es5ivy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ngcc && npm run test:jasmine -- --progress=false && npm run test:jest",
"test": "npm run test:jasmine -- --progress=false && npm run test:jest",
"test:jasmine": "ng test",
"test:jasmine:debug": "ng test -- --watch --browsers Chrome",
"test:jest": "jest --runInBand",
Expand Down
12 changes: 8 additions & 4 deletions lib/common/lib.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InjectionToken, PipeTransform, Provider } from '@angular/core';
import { getTestBed } from '@angular/core/testing';
import { getTestBed, MetadataOverride } from '@angular/core/testing';

import { MockedComponent } from '../mock-component';
import { MockedDirective } from '../mock-directive';
Expand Down Expand Up @@ -30,16 +30,20 @@ export interface NgModuleWithProviders<T = any> {
}

export const NG_MOCKS = new InjectionToken<Map<any, any>>('NG_MOCKS');
export const NG_MOCKS_TOUCHES = new InjectionToken<Set<any>>('NG_MOCKS_TOUCHES');
export const NG_MOCKS_OVERRIDES = new InjectionToken<Map<Type<any> | AbstractType<any>, MetadataOverride<any>>>(
'NG_MOCKS_OVERRIDES'
);

/**
* Can be changed any time.
*
* @internal
*/
export const getNgMocksFromTestBed = (): Map<any, any> | undefined => {
export const getTestBedInjection = <I>(token: Type<I> | InjectionToken<I>): I | undefined => {
const testBed: any = getTestBed();
try {
return testBed.inject ? testBed.inject(NG_MOCKS) : testBed.get(NG_MOCKS);
return testBed.inject ? testBed.inject(token) : testBed.get(token);
} catch (e) {
return undefined;
}
Expand Down Expand Up @@ -190,7 +194,7 @@ export function getMockedNgDefOf<T>(type: Type<T>, ngType: 'p'): Type<MockedPipe
export function getMockedNgDefOf(type: Type<any>): Type<any>;
export function getMockedNgDefOf(type: any, ngType?: any): any {
const source = type.mockOf ? type.mockOf : type;
const mocks = getNgMocksFromTestBed();
const mocks = getTestBedInjection(NG_MOCKS);

let mock: any;

Expand Down
Loading

0 comments on commit e034dd7

Please sign in to comment.