lundi 2 mai 2016

Cant access Model (function) in Directive while unit testing

Unit testing a Directive which uses ngModel that has several function including getAll(). Model gets injected perfectly (when I output it, it shows the accessible getters/setters/etc). I pass it to the element. Do a compile and digest.

Getting the error 'TypeError: Cannot read property 'getAll' of undefined' though.

'console.log('vehiclesModel', vehiclesModel.get('vehicles'));'

Outputs the stubbedData!

'use strict';
describe('Directive: selectBox', function () {

    beforeEach(module('sytacApp'));
    beforeEach(module('syt.templates'));

    var scope,
        httpBackend,
        $rootScope,
        $compile,
        element,
        vehiclesModel,
        stubbedData;

    beforeEach(function () {
        inject(function ($injector) {
            $compile = $injector.get('$compile');
        });
    });

    beforeEach(inject(function (_$rootScope_, _$httpBackend_, _vehiclesModel_, _stubbedData_) {

        httpBackend = _$httpBackend_;
        $rootScope = _$rootScope_;
        vehiclesModel = _vehiclesModel_;
        stubbedData = _stubbedData_;

        vehiclesModel.set('vehicles', {data: stubbedData.container});
        console.log('vehiclesModel', vehiclesModel.get('vehicles'));
    }));

    it('should process model data accordingly', function () {

        var element = angular.element('<select-box identifier="type" selectedidentifier="selectedType" model="vehiclesTypesModel" data-ng-model="vehiclesModel"></select-box>');

        element = $compile(element)(scope);
        scope.$digest();

        //......
    });
});

Question. Am I overlooking something?

Aucun commentaire:

Enregistrer un commentaire