简体   繁体   English

未定义容器,使用Jasmine测试小叶角度图

[英]Container not defined testing Leaflet angular Map using Jasmine

I am trying to test a service which has reference to map generated in directive (not third-party, own directive) 我正在尝试测试引用在指令(不是第三方,自己的指令)中生成的映射的服务

Here is my spec file 这是我的规格文件

       beforeEach(() => {
    inject(($injector: any, $rootScope: ng.IRootScopeService) => {
        $log = $injector.get('$log');
        $q = $injector.get('$q');
        $timeout = $injector.get('$timeout');
        _compile = $injector.get('$compile');
        _scope = $rootScope.$new();
    });
    serviceUnderTest = new mapServiceObj($log, $q, $timeout);
    var element = angular.element('<div id="map"></div>');
    element = _compile(element)(_scope);
    _scope.$digest();
    serviceUnderTest.map = L.map("map");
});

when I ran the tests i get an error at the last line saying that container not defined. 当我运行测试时,我在最后一行收到错误消息,提示未定义容器。 I think I am pretty close, Can someone Please point where my mistake is? 我想我很亲密,有人可以指出我的错误在哪里吗?

Figured it. 想通了。 Need to add to DOM. 需要添加到DOM。 Here is the fix. 解决方法是这里。

 var ele = angular.element('<div id="map"></div>');
    angular.element(document.body).append(ele);
    _compile(ele)(_scope);
    _scope.$digest();
    serviceUnderTest.map = L.map("map");

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

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