Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS Karma Jasmine指令测试不呈现html_Javascript_Html_Angularjs_Karma Jasmine - Fatal编程技术网

Javascript AngularJS Karma Jasmine指令测试不呈现html

Javascript AngularJS Karma Jasmine指令测试不呈现html,javascript,html,angularjs,karma-jasmine,Javascript,Html,Angularjs,Karma Jasmine,我正在学习Angular,我正在尝试用Karma Jasmine对指令进行测试。但是,似乎没有呈现指令的html模板(例如ng repeat,未被替换/处理)。我想测试classmdl-list\u item-sub-title的span的内容是否是预期的渲染输出 我的指令(views/customerslistdirection.html)如下所示: <!--Template for customer list directive--> <ul class="demo-lis

我正在学习Angular,我正在尝试用Karma Jasmine对指令进行测试。但是,似乎没有呈现指令的html模板(例如ng repeat,未被替换/处理)。我想测试class
mdl-list\u item-sub-title
的span的内容是否是预期的渲染输出

我的指令(
views/customerslistdirection.html
)如下所示:

<!--Template for customer list directive-->
<ul class="demo-list-two mdl-list">
    <li ng-repeat="user in e.users" class="mdl-list__item mdl-list__item--two-line">
    <span class="mdl-list__item-primary-content">
        <i class="material-icons mdl-list__item-avatar">person</i>
        <span>{{user.nome}}</span>
        <span class="mdl-list__item-sub-title">{{user.valor | currency:"R$"}} at {{user.data | date:'dd-MMM'}}</span>
    </span>
    <span class="mdl-list__item-secondary-content">
        <span class="mdl-list__item-secondary-info" ng-if="$first">VIP</span>
        <a class="mdl-list__item-secondary-action" href="#"><i class="material-icons" ng-if="user.valor >= 100">star</i></a>
    </span>
    </li>
我的测试规范:

describe("Test Customer List Directive", function(){
    beforeEach(module('ex1'));
    beforeEach(module('templates'));
    var compile, scope, directiveElement;

    beforeEach(inject(function($compile, $templateCache, $rootScope){
        compile = $compile;
        scope = $rootScope.$new();
        directiveElement = angular.element('<div customer-List></div>');
        compile(directiveElement)(scope);
        scope.$digest();
    }));

    it('basic test', function(){
        scope.$apply(function(){
            scope.users = [
                {
                    nome:"Alice",
                    data:"2016-05-02",
                    valor:100
                }
            ];
        });
        scope.$digest();

        var valor1 = directiveElement.find("<span class=\"mdl-list__item-sub-title\">");
        expect(valor1).toEqual('R$100 at 02-May');
    })
});
据我所知,我已经根据示例/规范和其他链接文章完成了所有工作。但是,在运行测试时,
directiveElement
变量的
innerHtml
的内容(我希望包含呈现的指令)仅包含:

<div customer-list="" class="ng-scope"><!--Template for customer list directive-->
<ul class="demo-list-two mdl-list">
    <!-- ngRepeat: user in e.users -->
</ul></div>


因此测试失败了。感谢您的帮助

乍一看,您的ng repeat似乎没有正确定义

似乎没有任何
e

ng-repeat="user in e.users"
但是你定义了你的范围

scope.users = [
            {
                nome:"Alice",
                data:"2016-05-02",
                valor:100
            }
        ];

您使用的stackoverflow链接已过时。去看医生:我也检查过了。例如,没有一个带有ng repeat的指令的例子,这是我的测试中没有编译/呈现的。你知道这一点吗?
ng-repeat="user in e.users"
scope.users = [
            {
                nome:"Alice",
                data:"2016-05-02",
                valor:100
            }
        ];