繁体   English   中英

单元测试指令和isolatedScope不是函数

[英]unit testing directive and isolatedScope not a function

我正在尝试对先前编写的指令进行单元测试,而对于我的第一个单元测试,我要做的就是检查指令范围内的变量。

但是,每次我尝试在html元素上运行方法isolatedScope()时,都会收到错误elem.isolatedScope is not a function

一件奇怪的事是,当我在javascript控制台上对元素运行$compile之后立即设置断点时,我能够打印指令隔离范围。

尝试将我的isolatedScope设置为如下所示的变量,将始终导致错误elem.isolatedScope is not a function

describe('directive: wikis', function() {
    var $scope, elem, isolated;

    beforeEach(module('app'));

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

        elem = angular.element('<wikis></wikis>');
        elem = _$compile_(elem)($scope);
        isolated = elem.isolatedScope()
        isolated.$digest();
    }));

    describe('$scope should be defined', function(){
        it('data should be empty object', function() {
            expect(isolated.data).to.be.null;
        });
    });
});

对我可能做错的事情有任何想法吗?

它是isolateScope ,而不是isolatedScope

隔离范围隔离范围的术语可以互换使用,但是第一个在官方资料来源中是首选的 (它可能是框架作者之一创造的):

我们想要做的是将指令内部的作用域与外部作用域分开,然后将外部作用域映射到指令的内部作用域。 我们可以通过创建隔离范围来做到这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM