jeudi 22 septembre 2016

Karma Testing with Angular 1 and Directive

I'm trying to add a test to assign value(foo) for an input in a directive using jqlite. What is wrong with the testing code?.

it('Simple Directive Testing', function () {
    scope.finalObj = {};
    scope.obj = {};
    scope.obj.schema = {"type": "object", "properties": {"number": {"type": "number"}, "street_name": {"type": "string"}, "street_type": {"type": "string"}}};
    //Functions to set value in scope

    dirElement = angular.element('<my-text id="number" label="number" name="gui.number" value="gui.number" final-obj="finalObj"></my-text>');
    compile(dirElement)(scope);
    scope.$digest();
    var dirElementInput = dirElement.find('number');
    console.log(dirElementInput[0]);
    dirElementInput.val('Foo').triggerHandler('input');
    scope.$apply();
    expect(scope.gui.number).toEqual(0);
});

This is the directive

<input type="text" name="" id="" ng-model="value" />

Aucun commentaire:

Enregistrer un commentaire