Created
March 10, 2021 16:41
-
-
Save nilsandrey/d4f63a7f9802d5cb5f9aa3e8898a687e to your computer and use it in GitHub Desktop.
How to mock Pipe when testing Component (https://stackoverflow.com/a/56701741/2100126)
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
// If you want reusable util function for mocking pipes, you can try this option: | |
export function mockPipe(options: Pipe): Pipe { | |
const metadata: Pipe = { | |
name: options.name | |
}; | |
return <any>Pipe(metadata)(class MockPipe {}); | |
} | |
// ... |
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
// And then just call this function inside the TestBed declarations array: | |
TestBed.configureTestingModule({ | |
declarations: [ | |
SomeComponent, | |
mockPipe({ name: 'myPipe' }), | |
mockPipe({ name: 'myOtherPipe' }) | |
], | |
// ... | |
}).compileComponents(); | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment