-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(MockBuilder): params support tokens and modules with providers #762
- Loading branch information
Showing
7 changed files
with
230 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Injectable, NgModule } from '@angular/core'; | ||
import { | ||
MockBuilder, | ||
MockRender, | ||
NgModuleWithProviders, | ||
} from 'ng-mocks'; | ||
|
||
@Injectable() | ||
class TargetService { | ||
public readonly name?: string = 'target'; | ||
} | ||
|
||
@NgModule() | ||
class TargetModule { | ||
public static forRoot(): NgModuleWithProviders<TargetModule> { | ||
return { | ||
ngModule: TargetModule, | ||
providers: [TargetService], | ||
}; | ||
} | ||
} | ||
|
||
describe('issue-762:module', () => { | ||
describe('as keep single', () => { | ||
beforeEach(() => MockBuilder(TargetModule.forRoot())); | ||
|
||
it('works correctly', () => { | ||
const fixture = MockRender(TargetService); | ||
expect(fixture.point.componentInstance).toEqual( | ||
jasmine.any(TargetService), | ||
); | ||
expect(fixture.point.componentInstance.name).toEqual('target'); | ||
}); | ||
}); | ||
|
||
describe('as keep multi', () => { | ||
beforeEach(() => MockBuilder([TargetModule.forRoot()])); | ||
|
||
it('works correctly', () => { | ||
const fixture = MockRender(TargetService); | ||
expect(fixture.point.componentInstance).toEqual( | ||
jasmine.any(TargetService), | ||
); | ||
expect(fixture.point.componentInstance.name).toEqual('target'); | ||
}); | ||
}); | ||
|
||
describe('as mock single', () => { | ||
beforeEach(() => MockBuilder(null, TargetModule.forRoot())); | ||
|
||
it('works correctly', () => { | ||
const fixture = MockRender(TargetService); | ||
expect(fixture.point.componentInstance).toEqual( | ||
jasmine.any(TargetService), | ||
); | ||
expect(fixture.point.componentInstance.name).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('as mock multi', () => { | ||
beforeEach(() => MockBuilder(null, [TargetModule.forRoot()])); | ||
|
||
it('works correctly', () => { | ||
const fixture = MockRender(TargetService); | ||
expect(fixture.point.componentInstance).toEqual( | ||
jasmine.any(TargetService), | ||
); | ||
expect(fixture.point.componentInstance.name).toEqual(undefined); | ||
}); | ||
}); | ||
}); |
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,70 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { MockBuilder } from 'ng-mocks'; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: 'STRING', | ||
useValue: 'TOKEN', | ||
}, | ||
], | ||
}) | ||
class TargetModule {} | ||
|
||
describe('issue-762:string', () => { | ||
describe('as keep single lonely', () => { | ||
beforeEach(() => MockBuilder('STRING')); | ||
|
||
it('works correctly', () => { | ||
expect(() => TestBed.get('STRING')).toThrowError( | ||
/No provider for STRING/, | ||
); | ||
}); | ||
}); | ||
|
||
describe('as keep single', () => { | ||
beforeEach(() => MockBuilder('STRING', TargetModule)); | ||
|
||
it('works correctly', () => { | ||
const token = TestBed.get('STRING'); | ||
expect(token).toEqual('TOKEN'); | ||
}); | ||
}); | ||
|
||
describe('as keep multi', () => { | ||
beforeEach(() => MockBuilder(['STRING'], TargetModule)); | ||
|
||
it('works correctly', () => { | ||
const token = TestBed.get('STRING'); | ||
expect(token).toEqual('TOKEN'); | ||
}); | ||
}); | ||
|
||
describe('as mock single lonely', () => { | ||
beforeEach(() => MockBuilder(null, 'STRING')); | ||
|
||
it('works correctly', () => { | ||
const token = TestBed.get('STRING'); | ||
expect(token).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('as mock single', () => { | ||
beforeEach(() => MockBuilder(TargetModule, 'STRING')); | ||
|
||
it('works correctly', () => { | ||
const token = TestBed.get('STRING'); | ||
expect(token).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('as mock multi', () => { | ||
beforeEach(() => MockBuilder(TargetModule, ['STRING'])); | ||
|
||
it('works correctly', () => { | ||
const token = TestBed.get('STRING'); | ||
expect(token).toEqual(undefined); | ||
}); | ||
}); | ||
}); |
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,71 @@ | ||
import { InjectionToken, NgModule } from '@angular/core'; | ||
import { MockBuilder, MockRender } from 'ng-mocks'; | ||
|
||
const TOKEN = new InjectionToken('TOKEN'); | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ | ||
provide: TOKEN, | ||
useValue: 'TOKEN', | ||
}, | ||
], | ||
}) | ||
class TargetModule {} | ||
|
||
describe('issue-762:token', () => { | ||
describe('as keep single lonely', () => { | ||
beforeEach(() => MockBuilder(TOKEN)); | ||
|
||
it('works correctly', () => { | ||
expect(() => MockRender(TOKEN)).toThrowError( | ||
/No provider for InjectionToken TOKEN/, | ||
); | ||
}); | ||
}); | ||
|
||
describe('as keep single', () => { | ||
beforeEach(() => MockBuilder(TOKEN, TargetModule)); | ||
|
||
it('works correctly', () => { | ||
const fixture = MockRender(TOKEN); | ||
expect(fixture.point.componentInstance).toEqual('TOKEN'); | ||
}); | ||
}); | ||
|
||
describe('as keep multi', () => { | ||
beforeEach(() => MockBuilder([TOKEN], TargetModule)); | ||
|
||
it('works correctly', () => { | ||
const fixture = MockRender(TOKEN); | ||
expect(fixture.point.componentInstance).toEqual('TOKEN'); | ||
}); | ||
}); | ||
|
||
describe('as mock single lonely', () => { | ||
beforeEach(() => MockBuilder(null, TOKEN)); | ||
|
||
it('works correctly', () => { | ||
const fixture = MockRender(TOKEN); | ||
expect(fixture.point.componentInstance).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('as mock single', () => { | ||
beforeEach(() => MockBuilder(TargetModule, TOKEN)); | ||
|
||
it('works correctly', () => { | ||
const fixture = MockRender(TOKEN); | ||
expect(fixture.point.componentInstance).toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('as mock multi', () => { | ||
beforeEach(() => MockBuilder(TargetModule, [TOKEN])); | ||
|
||
it('works correctly', () => { | ||
const fixture = MockRender(TOKEN); | ||
expect(fixture.point.componentInstance).toEqual(undefined); | ||
}); | ||
}); | ||
}); |