I've created a directive that generates input fields and connects them to the scope using ngModel
. When a user uses this directive in the HTML file like so:
<div tk-quick-form="formStructure" form-data="formData" id="main_form" ></div>
and adds the following in the controller:
$scope.formStructure = [
{
fieldName: 'name',
type: 'string'
}
];
Then an input field is created with ngModel
linking to formData.name
.
The directive functions correctly, but I'm unsure how to test it using Jasmine.
Here's what I have tried so far:
Within the it
function:
$rootScope.formStructure = [
{
fieldName: 'name',
type: 'string'
}
];
var element = $compile('<div tk-quick-form="formStructure" form-data="formData" id="main_form" ></div>"')($rootScope);
$(element).find("input#name").val("set")
dump($(element).find("input#name").val()) // outputs "set"
expect($rootScope.formData.name).toBe("set"); //outputs Expected undefined to have value 'set'
//(though in manual testing $scope.formData.name is actually set because the input field contains ng-model="formData.name")
$rootScope.$digest();
How should I go about writing this test case?