下面是一个简单的Jasmine测试。出于某种原因,expect(scope.myForm.$invalid).toBe(true)
失败了。其他测试正在通过。
我无法弄清楚原因。
谢谢!
describe('angularValidator', function() {
beforeEach(module('angularValidator'));
var scope, compile;
beforeEach(inject(function($rootScope, $compile) {
scope = $rootScope.$new();
compile = $compile;
var htmlForm = "<form name=\"myForm\">"
+ "<input type = \"text\""
+ "name = \"firstName\""
+ "ng-model = \"firstName\""
+ "required></form>";
element = compile(htmlForm)(scope);
}));
it('Initial should be pristine and invalid', function () {
expect(scope.myForm.$pristine).toBe(true);
expect(element.hasClass('ng-pristine')).toBe(true);
expect(scope.myForm.$invalid).toBe(true);
});