Skip to content

Instantly share code, notes, and snippets.

@nilsandrey
Created March 10, 2021 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsandrey/d4f63a7f9802d5cb5f9aa3e8898a687e to your computer and use it in GitHub Desktop.
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)
// 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 {});
}
// ...
// 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