-
-
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(MockBuilder): respects global configuration for standalone depend…
…encies #3161 MockBuilder will process dependencies of standalone declarations with respect of the next configuration: - ngMocks.globalKeep - ngMocks.globalMock - ngMocks.globalReplace - ngMocks.globalExclude
- Loading branch information
Showing
5 changed files
with
224 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
Component, | ||
Input, | ||
NgModule, | ||
Pipe, | ||
PipeTransform, | ||
VERSION, | ||
} from '@angular/core'; | ||
|
||
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
@Pipe({ | ||
name: 'translate', | ||
}) | ||
class TranslatePipe implements PipeTransform { | ||
transform(value: string) { | ||
return `${this.constructor.name}:real:${value}`; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [TranslatePipe], | ||
exports: [TranslatePipe], | ||
}) | ||
class TranslateModule {} | ||
|
||
ngMocks.globalExclude(TranslateModule); | ||
|
||
@Component( | ||
{ | ||
selector: 'standalone', | ||
standalone: true, | ||
template: `{{ name | translate }}`, | ||
imports: [TranslateModule], | ||
} as never /* TODO: remove after upgrade to a14 */, | ||
) | ||
class StandaloneComponent { | ||
@Input() public readonly name: string = ''; | ||
} | ||
|
||
// @see https://github.com/help-me-mom/ng-mocks/issues/3161 | ||
describe('issue-3161:exclude', () => { | ||
if (Number.parseInt(VERSION.major, 10) < 14) { | ||
it('needs a14', () => { | ||
// pending('Need Angular > 5'); | ||
expect(true).toBeTruthy(); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
beforeEach(() => MockBuilder(StandaloneComponent)); | ||
|
||
it('fails because of excluded module', () => { | ||
expect(() => | ||
MockRender(StandaloneComponent, { | ||
name: 'sandbox', | ||
}), | ||
).toThrowError(/The pipe 'translate' could not be found/); | ||
}); | ||
}); |
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,63 @@ | ||
import { | ||
Component, | ||
Input, | ||
NgModule, | ||
Pipe, | ||
PipeTransform, | ||
VERSION, | ||
} from '@angular/core'; | ||
|
||
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
@Pipe({ | ||
name: 'translate', | ||
}) | ||
class TranslatePipe implements PipeTransform { | ||
transform(value: string) { | ||
return `${this.constructor.name}:real:${value}`; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [TranslatePipe], | ||
exports: [TranslatePipe], | ||
}) | ||
class TranslateModule {} | ||
|
||
ngMocks.globalKeep(TranslateModule); | ||
|
||
@Component( | ||
{ | ||
selector: 'standalone', | ||
standalone: true, | ||
template: `{{ name | translate }}`, | ||
imports: [TranslateModule], | ||
} as never /* TODO: remove after upgrade to a14 */, | ||
) | ||
class StandaloneComponent { | ||
@Input() public readonly name: string = ''; | ||
} | ||
|
||
// @see https://github.com/help-me-mom/ng-mocks/issues/3161 | ||
describe('issue-3161:keep', () => { | ||
if (Number.parseInt(VERSION.major, 10) < 14) { | ||
it('needs a14', () => { | ||
// pending('Need Angular > 5'); | ||
expect(true).toBeTruthy(); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
beforeEach(() => MockBuilder(StandaloneComponent)); | ||
|
||
it('uses the original pipe', () => { | ||
const fixture = MockRender(StandaloneComponent, { | ||
name: 'sandbox', | ||
}); | ||
|
||
expect(ngMocks.formatText(fixture)).toEqual( | ||
'TranslatePipe:real:sandbox', | ||
); | ||
}); | ||
}); |
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,78 @@ | ||
import { | ||
Component, | ||
Input, | ||
NgModule, | ||
Pipe, | ||
PipeTransform, | ||
VERSION, | ||
} from '@angular/core'; | ||
|
||
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
@Pipe({ | ||
name: 'translate', | ||
}) | ||
class TranslatePipe implements PipeTransform { | ||
transform(value: string) { | ||
return `${this.constructor.name}:real:${value}`; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [TranslatePipe], | ||
exports: [TranslatePipe], | ||
}) | ||
class TranslateModule {} | ||
|
||
@Pipe({ | ||
name: 'translate', | ||
}) | ||
class MockTranslatePipe implements PipeTransform { | ||
transform(value: string) { | ||
return `${this.constructor.name}:mock:${value}`; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [MockTranslatePipe], | ||
exports: [MockTranslatePipe], | ||
}) | ||
class MockTranslateModule {} | ||
|
||
ngMocks.globalReplace(TranslateModule, MockTranslateModule); | ||
|
||
@Component( | ||
{ | ||
selector: 'standalone', | ||
standalone: true, | ||
template: `{{ name | translate }}`, | ||
imports: [TranslateModule], | ||
} as never /* TODO: remove after upgrade to a14 */, | ||
) | ||
class StandaloneComponent { | ||
@Input() public readonly name: string = ''; | ||
} | ||
|
||
// @see https://github.com/help-me-mom/ng-mocks/issues/3161 | ||
describe('issue-3161', () => { | ||
if (Number.parseInt(VERSION.major, 10) < 14) { | ||
it('needs a14', () => { | ||
// pending('Need Angular > 5'); | ||
expect(true).toBeTruthy(); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
beforeEach(() => MockBuilder(StandaloneComponent)); | ||
|
||
it('uses replaced pipe', () => { | ||
const fixture = MockRender(StandaloneComponent, { | ||
name: 'sandbox', | ||
}); | ||
|
||
expect(ngMocks.formatText(fixture)).toEqual( | ||
'MockTranslatePipe:mock:sandbox', | ||
); | ||
}); | ||
}); |