forked from help-me-mom/ng-mocks
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): respecting transform in mock pipes help-me-mom#4564
- Loading branch information
Showing
4 changed files
with
75 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { | ||
Component, | ||
NgModule, | ||
Pipe, | ||
PipeTransform, | ||
} from '@angular/core'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { MockModule, MockPipe, MockRender, ngMocks } from 'ng-mocks'; | ||
|
||
@Pipe({ | ||
name: 'target', | ||
}) | ||
class TargetPipe implements PipeTransform { | ||
transform() { | ||
return 'real'; | ||
} | ||
} | ||
|
||
@Pipe({ | ||
name: 'standard', | ||
}) | ||
class StandardPipe implements PipeTransform { | ||
transform() { | ||
return 'standard'; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [TargetPipe, StandardPipe], | ||
exports: [TargetPipe, StandardPipe], | ||
}) | ||
class PipeModule {} | ||
|
||
@Component({ | ||
selector: 'target', | ||
template: '<span> {{ null | target }}</span>', | ||
}) | ||
class TargetComponent {} | ||
|
||
@NgModule({ | ||
imports: [PipeModule], | ||
declarations: [TargetComponent], | ||
exports: [TargetComponent], | ||
}) | ||
class ComponentModule {} | ||
|
||
// @see https://github.com/help-me-mom/ng-mocks/issues/4564 | ||
// mixed imports forget pipe customizations. | ||
describe('issue-4564', () => { | ||
beforeEach(() => | ||
TestBed.configureTestingModule({ | ||
imports: [ComponentModule, MockModule(PipeModule)], | ||
declarations: [ | ||
MockPipe(TargetPipe, () => 'mock'), | ||
MockPipe(StandardPipe), | ||
], | ||
}).compileComponents(), | ||
); | ||
|
||
it('customizes pipe', () => { | ||
const fixture = MockRender(TargetComponent); | ||
expect(ngMocks.formatText(fixture)).toEqual('mock'); | ||
}); | ||
}); |