[Unit Testing] Directive testing. 1

describe("Hello world",function(){
    var element;
    var $scope;
    beforeEach(module("app"))
    beforeEach(inject(function($compile, $rootScope){
        $scope = $rootScope;
        element = angular.element("<div test-dir>{{2+5}}</div>");
        element = $compile(element)($rootScope);
    }))

    it("Should be 7",function(){
        $scope.$digest();
        expect(element.html()).toBe("7")
    })

    describe("testDir", function() {
        it("should add a class of panel", function() {
            expect(element.hasClass("panel")).toBe(true);
        })
    })

})

 

app.directive('testDir',function(){
    return function(scope, element){
        element.addClass('panel');
    }
})

 

posted @ 2014-09-02 03:02  Zhentiw  阅读(151)  评论(0)    收藏  举报