-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: respecting mock keep switch in nested modules
- Loading branch information
Showing
5 changed files
with
124 additions
and
27 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,81 @@ | ||
import { Component, NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { MockBuilder, MockRender } from 'ng-mocks'; | ||
|
||
// This directive is shared via a module that is actually is kept in one and is mocked in another one. | ||
@Component({ | ||
selector: 'shared', | ||
template: 'shared', | ||
}) | ||
class SharedComponent {} | ||
|
||
@NgModule({ | ||
declarations: [SharedComponent], | ||
exports: [SharedComponent], | ||
}) | ||
class SharedModule {} | ||
|
||
@NgModule({ | ||
exports: [SharedModule], | ||
imports: [SharedModule], | ||
}) | ||
class MockModule {} | ||
|
||
@NgModule({ | ||
exports: [SharedModule], | ||
imports: [SharedModule], | ||
}) | ||
class KeepModule {} | ||
|
||
@Component({ | ||
selector: 'target', | ||
template: 'target', | ||
}) | ||
class TargetComponent {} | ||
|
||
@NgModule({ | ||
bootstrap: [TargetComponent], | ||
declarations: [TargetComponent], | ||
imports: [BrowserModule, BrowserAnimationsModule, KeepModule, MockModule], | ||
providers: [], | ||
}) | ||
export class TargetModule {} | ||
|
||
describe('issue-222:mock-keep-priorities', () => { | ||
describe('keep', () => { | ||
beforeEach(() => MockBuilder(TargetComponent, TargetModule).keep(KeepModule)); | ||
|
||
it('keeps all child imports', () => { | ||
const fixture = MockRender(SharedComponent); | ||
expect(fixture.nativeElement.innerHTML).toEqual('<shared>shared</shared>'); | ||
}); | ||
}); | ||
|
||
describe('mock', () => { | ||
beforeEach(() => MockBuilder(TargetComponent, TargetModule).keep(KeepModule).mock(SharedModule)); | ||
|
||
it('mocks the nested module of a kept module', () => { | ||
const fixture = MockRender(SharedComponent); | ||
expect(fixture.nativeElement.innerHTML).toEqual('<shared></shared>'); | ||
}); | ||
}); | ||
|
||
describe('reverse', () => { | ||
beforeEach(() => MockBuilder(TargetComponent, TargetModule).mock(KeepModule).keep(SharedModule)); | ||
|
||
it('keeps the nested module of a mocked module', () => { | ||
const fixture = MockRender(SharedComponent); | ||
expect(fixture.nativeElement.innerHTML).toEqual('<shared>shared</shared>'); | ||
}); | ||
}); | ||
|
||
describe('mock keep priority', () => { | ||
beforeEach(() => MockBuilder(TargetComponent, TargetModule).keep(KeepModule).mock(MockModule)); | ||
|
||
it('keep wins', () => { | ||
const fixture = MockRender(SharedComponent); | ||
expect(fixture.nativeElement.innerHTML).toEqual('<shared>shared</shared>'); | ||
}); | ||
}); | ||
}); |