2017-04-13 4 views
0

AngularJS 프로젝트에 연속 통합을 추가하려고하지만 일부 지시문 테스트가 실패합니다. 이 테스트는 로컬에서만 잘 수행됩니다. 아래의 오류 코드는 내가 얻은 모든 오류와 유사합니다.

오류 코드

PhantomJS 2.1.1 (Linux 0.0.0) myHead directive compiles a my-head attribute FAILED 
    .... 
    TypeError: undefined is not a function (evaluating '$compile('<div my-head></div>')') in /home/travis/build/../../test/unit/myHeadDirective.js (line 15) 
    .... 

주입이 시험에 포함되는 동안 $ 컴파일 기능의 주입이 작동하지 않는 것 같다.

테스트 코드

describe('myHead directive', function() { 
    var $compile, $rootScope 

    beforeEach(module('myApp.templates')) 
    beforeEach(module('myApp.directives')) 

    beforeEach(inject(function (_$compile_, _$rootScope_) { 
    $compile = _$compile_ 
    $rootScope = _$rootScope_ 
    })) 

    it('compiles a my-head attribute', function() { 
    var compiledElement = $compile('<div my-head></div>')($rootScope) 
    $rootScope.$digest() // Fire watchers 
    expect(compiledElement.html()).toContain('tg_page_head') 
    }) 

    it('compiles a my-head element', function() { 
    var compiledElement = $compile('<my-head></my-head>')($rootScope) 
    $rootScope.$digest() // Fire watchers 
    expect(compiledElement.html()).toContain('tg_page_head') 
    }) 
}) 

내가 트래비스를 사용하여 새로운 해요, 그래서 트래비스 설정이 문제가 될 수있는 설정을 선택합니다. 은 $ 컴파일 함수가 정의되지 않는 이유

#.travis.yml 

language: node_js 
sudo: false 
node_js: 
    - '6' 

cache: 
    yarn: true 

env: 
    global: 
    - CXX=g++-4.8 # node 4 likes the G++ v4.8 compiler 

addons: 
    apt: 
    sources: 
     - ubuntu-toolchain-r-test 
    packages: 
     - g++-4.8 
    code_climate: 
    repo_token: '......' 


before_script: 
    - npm install -g gulp 
    - npm install -g 

script: 
    - gulp build 
    - gulp test 

그래서, 사람이 을 알고 않는 (비 관련 부분의 일부가 제거됩니다)?

답변

0

문제가 해결되었습니다. 테스트를 실행하기 전에 templates.js를 생성해야합니다. .travis.yml의 before_script에 generate 스크립트를 추가하여 $ compile 함수가 작동하도록했습니다.

before_script: 
    - npm install -g gulp 
    - npm install -g 
    - gulp templates 

script: 
    - gulp test 
    - gulp build 
:

그래서,이 새로운 before_script입니다