I have been learning AngularJS and things have been going pretty smoothly regarding unit testing, but I've reached a bit of a tricky spot.
Suppose I have a simple form, for example:
<form name="form">
<input type="text" name="number" ng-pattern="/^d+$/">
</form>
If I was testing something like a controller, I know that I would write it something like this (using Jasmine + Karma):
beforeEach(module('some.module'));
beforeEach(inject(/* services */) {
/* inject necessary services */
});
it('should be invalid when given bad input', function () {
form.number = 'Not a number';
expect(form.number.$valid).toBeFalsy();
expect(form.$valid).toBeFalsy();
});
But I don't know which services I need to inject, and I haven't had any luck finding documentation on unit testing in either the forms
guide or the ng-form
documentation.
How does one unit test a form in Angular?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…