2016-07-21 82 views
0

我已经使用了哟角1生成器,它创建了一个着陆页和一些测试。我无法编译VS中的代码,因为“module('fountainFooter');”未定义。角度测试与业力

/// <reference path="../../typings/index.d.ts" /> 

import * as angular from 'angular'; 
import 'angular-mocks'; 
import {footer} from './footer.ts'; 

describe('footer component',() => { 
    beforeEach(() => { 
    angular 
     .module('fountainFooter', ['src/app/footer.html']) 
     .component('fountainFooter', footer); 
    module('fountainFooter'); 
    }); 

    it('should render \'FountainJS team\'', inject(($rootScope: ng.IRootScopeService, $compile: ng.ICompileService) => { 
    const element = $compile('<fountain-footer></fountain-footer>')($rootScope); 
    $rootScope.$digest(); 
    const footer = element.find('a'); 
    expect(footer.html().trim()).toEqual('FountainJS team'); 
    })); 
}); 

我猜测模块处于角嘲笑限定的模块,所以我试图声明模块作为angular.mock.module。但是当我这样做时,我得到这个错误:

PhantomJS 2.1.1 (Windows 8 0.0.0) footer component should render 'FountainJS team' FAILED 
     TypeError: undefined is not an object (evaluating 'angular.mock.module') (line 21) 

据我了解,模块是在浏览器窗口中声明。只使用gulp和systemjs模块工作。当我使用angular-mock.module时,VS和打字稿很高兴,但是诅咒什么都行不通。

回答

0

这是一种方法。

/// <reference path="../../typings/index.d.ts" /> 

describe('footer component',() => { 
    beforeEach(angular.mock.module('app', ($provide: ng.auto.IProvideService) => { 
    $provide.factory('fountainFooter',() => { 
     return { 
     templateUrl: 'app/footer.html' 
     }; 
    }); 
    })); 
    it('should render \'FountainJS team\'', inject(($rootScope: ng.IRootScopeService, $compile: ng.ICompileService) => { 
    const element = $compile('<fountain-footer></fountain-footer>')($rootScope); 
    $rootScope.$digest(); 
    const footer = element.find('a'); 
    expect(footer.html().trim()).toEqual('FountainJS team'); 
    })); 
}); 

也取自yo angular#1生成器,但使用选项脚本注入生成。