lundi 26 janvier 2015

Cannot call $scope.form.$submitted in jasmine test: undefined

Angularjs 1.3.0-beta.8


I am trying to test wether a form was submitted or not.


Here is the test



it ('should submit when I TELL IT TO DO SO!!!', function(){
element.find('button').trigger('click'); // form button that calls submit funtion
expect( element.isolateScope().validationFieldsForm.$valid ).toBe( true );
});


The above test works just fine. I have access to $valid as I should. However, when I run the same test again but revised like this...



it ('should submit when I TELL IT TO DO SO!!!', function(){
element.find('button').trigger('click'); // form button that calls submit funtion
expect( element.isolateScope().validationFieldsForm.$submitted ).toBe( true );
});


The test above will result in 'undefined'. In fact, if I even call $scope.myFormName.$submitted in the directive this does not work either, but $error, $valid, $invalid, $setValidity, etc... all work.


Angularjs says that $submitted should be available in the form control object.



angularjs form controller



Aucun commentaire:

Enregistrer un commentaire