-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
228 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
|
||
import { AnyType } from '../common/core.types'; | ||
import ngMocksUniverse from '../common/ng-mocks-universe'; | ||
|
||
export default (source: AnyType<any> | InjectionToken<any>): void => { | ||
ngMocksUniverse.getDefaults().set(source, null); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Component, NgModule } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'target', | ||
template: '{{ name }}', | ||
}) | ||
export class Target1Component { | ||
public readonly name = 'target1'; | ||
} | ||
|
||
@NgModule({ | ||
declarations: [Target1Component], | ||
exports: [Target1Component], | ||
}) | ||
export class Target1Module {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { MockModule, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
import { Target1Module } from './fixtures'; | ||
|
||
ngMocks.defaultExclude(Target1Module); | ||
|
||
// The root module we pass into MockModule isn't excluded despite the setting. | ||
describe('ng-mocks-default-exclude-modules', () => { | ||
beforeEach(() => { | ||
return TestBed.configureTestingModule({ | ||
imports: [MockModule(Target1Module)], | ||
}); | ||
}); | ||
|
||
it('mocks Target1Component', () => { | ||
const fixture = MockRender('<target></target>'); | ||
expect(fixture.nativeElement.innerHTML).toEqual( | ||
'<target></target>', | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { Component, NgModule } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { | ||
MockBuilder, | ||
MockComponent, | ||
MockModule, | ||
MockRender, | ||
ngMocks, | ||
} from 'ng-mocks'; | ||
|
||
@Component({ | ||
selector: 'target', | ||
template: '{{ name }}', | ||
}) | ||
class TargetComponent { | ||
public readonly name = 'target'; | ||
} | ||
|
||
@Component({ | ||
selector: 'target', | ||
template: '{{ name }}', | ||
}) | ||
class FakeComponent { | ||
public readonly name = 'fake'; | ||
} | ||
|
||
@NgModule({ | ||
declarations: [TargetComponent], | ||
exports: [TargetComponent], | ||
}) | ||
class TargetModule {} | ||
|
||
ngMocks.defaultExclude(TargetComponent); | ||
|
||
describe('ng-mocks-default-exclude', () => { | ||
describe('MockComponent', () => { | ||
beforeEach(() => | ||
TestBed.configureTestingModule({ | ||
declarations: [MockComponent(TargetComponent)], | ||
}), | ||
); | ||
|
||
it('works as usual', () => { | ||
const fixture = MockRender('<target></target>'); | ||
expect(fixture.nativeElement.innerHTML).toEqual( | ||
'<target></target>', | ||
); | ||
}); | ||
}); | ||
|
||
describe('MockModule', () => { | ||
beforeEach(() => | ||
TestBed.configureTestingModule({ | ||
imports: [MockModule(TargetModule)], | ||
}), | ||
); | ||
|
||
it('excludes out of the box', () => { | ||
expect(() => MockRender('<target></target>')).toThrow(); | ||
}); | ||
}); | ||
|
||
describe('MockBuilder:default', () => { | ||
beforeEach(() => MockBuilder(null, TargetModule)); | ||
|
||
it('excludes out of the box', () => { | ||
expect(() => MockRender('<target></target>')).toThrow(); | ||
}); | ||
}); | ||
|
||
describe('MockBuilder:keep', () => { | ||
beforeEach(() => | ||
MockBuilder(null, TargetModule).keep(TargetComponent), | ||
); | ||
|
||
it('switches to keep', () => { | ||
const fixture = MockRender('<target></target>'); | ||
expect(fixture.nativeElement.innerHTML).toEqual( | ||
'<target>target</target>', | ||
); | ||
}); | ||
}); | ||
|
||
describe('MockBuilder:mock', () => { | ||
beforeEach(() => | ||
MockBuilder(null, TargetModule).mock(TargetComponent), | ||
); | ||
|
||
it('switches to mock', () => { | ||
const fixture = MockRender('<target></target>'); | ||
expect(fixture.nativeElement.innerHTML).toEqual( | ||
'<target></target>', | ||
); | ||
}); | ||
}); | ||
|
||
describe('MockBuilder:replace', () => { | ||
beforeEach(() => | ||
MockBuilder(null, TargetModule).replace( | ||
TargetComponent, | ||
FakeComponent, | ||
), | ||
); | ||
|
||
it('switches to replace', () => { | ||
const fixture = MockRender('<target></target>'); | ||
expect(fixture.nativeElement.innerHTML).toEqual( | ||
'<target>fake</target>', | ||
); | ||
}); | ||
}); | ||
}); |