mardi 7 juillet 2015

Unit Test not giving expected error on grunt dev-test check

I am trying to begin to run unit tests while learning MEAN using grunt dev-test to check the following, which should return an error. However, in the terminal grunt dev-test detects the file as being changed and reports no errors.

'use strict';

describe('appMyDirective', function() {
    var elm, elmScope, $scope, $compile, $timeout;

beforeEach(module('myApp'));

/**
@param params
    @param {String} html
*/
var createElm =function(params) {
    var html ="<div app-my-directive>"+
    "</div>";
    if(params.html) {
        html =params.html;
    }
    // elm =angular.element(html);
    elm =$compile(html)($scope);
    // $scope.$digest();
    $scope.$apply();        //NOTE: required otherwise the alert directive won't be compiled!!!! ... wtf?
    elmScope =elm.isolateScope();
    var elements ={
        // 'somePart':elm.find('div').children().find('div')
    };
    return elements;
};

beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_) {
    $compile = _$compile_;
    $timeout = _$timeout_;
    $scope = _$rootScope_.$new();
}));

// afterEach(function() {
// });


it('should have a scopeOne property', function() {
    $scope.scopeOne ='test scope one';
    var html ="<div app-my-directive scope-one='scopeOne'></div>";
    createElm({html:html});
    expect(elmScope).toBe('test scope one1');
    });
});

Since $scope.scopeOne ='test scope one'; and I expect 'test scope one1' this should not pass as it is 'untruthy'. Or am I doing something wrong here?

enter image description here

Aucun commentaire:

Enregistrer un commentaire