DEV Community

Discussion on: An Angular Testing Cheatsheet

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
lysofdev profile image
Esteban Hernández

Hey, try separating your large function into smaller ones that can be tested in isolation.

If you have several simple pipes that depend on each other, try combining them in a custom pipe and test that with a mock observable.

So for RxJS, you can:

  • Test a simple function by using mocked inputs.
  • Test a custom pipe by using a mocked observable.
  • Test a custom observable by mocking the sources or events.

My general rule of thumb is that a function should hardly ever have more than two or three tests. When a function requires more than that, you can probably break it down into two or more.