Testing Components
When developing an app it's important to cover it with automated tests. The components of ngBackbone are friendly for unit-testings. Examine the tests covering demo app
For testing purposes we can initialize a component out of it context:
By passing el: null
we tell the Backbone to not bind the component despite configuration given with @Component
. Instead it creates a new element ng-hero
that we can refer as view.el
First we check if the template string bound to the component has no syntax errors:
Then we can cast different states to controls and groups and verify if the template responds as intended:
We can also test how the component responds to user input.
Here we change value of an input by using testInput
method. It makes FormView
to run validation the same way as if the change was received from real input event. Type validation is asynchronous thus the method returns a promise where we can assert states of the control and the group.
Last updated