Answers

Question and Answer:

  Home  AngularJS Developer

⟩ Explain me what are the basic steps to unit test an AngularJS filter?

1. Inject the module that contains the filter.

2. Provide any mocks that the filter relies on.

3. Get an instance of the filter using $filter('yourFilterName').

4. Assert your expectations.

Dependency injection is a powerful software design pattern that Angular employs to compose responsibilities through an intrinsic interface. However, for those new to the process, it can be puzzling where you need to configure and mock these dependencies when creating your isolated unit tests. The open-source project “Angular Test Patterns” is a free resource that is focused on dispelling such confusion through high-quality examples.

This question is useful since it can give you a feel for how familiar the candidate is with automated testing (TDD, BDD, E2E), as well as open up a conversation about approaches to code quality.

 177 views

More Questions for you: