2016-05-17 8 views
2

私はAngularJS 1.5.5で本当に簡単なディレクティブをテストしようとしています。未定義はコンストラクタではない、angularjsディレクティブテスト

ディレクティブ自体:

angular.module('whatToPlayWithFriendsApp.card').directive('card', function() { 
    return { 
    restrict: 'EA', 
    link: function link(scope, element, attrs) { 
     element.bind('click', function() { 
     angular.element(this).toggleClass('selected'); 
     }); 
    } 
    }; 
}); 

テスト:

'use strict'; 

describe('Directive: card', function() { 

    // load the directive's module 
    beforeEach(module('myApp.card')); 

    var element, scope; 

    beforeEach(inject(function ($rootScope) { 
    scope = $rootScope.$new(); 
    })); 

    it('should make element to have selected class on click', inject(function ($compile) { 
    element = angular.element('<div card></div>'); 
    $compile(element)(scope); 
    scope.$digest(); 
    element.triggerHandler('click'); 
    expect(element.hasClass('selected')).toBe(true); 
    })); 
}); 

しかし、私のテストは、このエラーのため失敗します。

Undefined is not a constructor (evaluating 'expect(element.hasClass('selected')).toBe(true)') 

私はこの問題を見上げ:https://github.com/angular/angular.js/issues/14251 私はすべてのanglejsスイートに同じバージョンを使用しています。私はここで何が欠けていますか? (一気テスト:クライアント):

gulp.task('test:client', ['wiredep:test', 'constant'], (done) => { 
    new KarmaServer({ 
     configFile: `${__dirname}/${paths.karma}`, 
     singleRun: true 
    }, done).start(); 
}); 

gulp.task('wiredep:test',() => { 
    return gulp.src(paths.karma) 
     .pipe(wiredep({ 
      exclude: [ 
       '/json3/', 
       '/es5-shim/', 
       /font-awesome\.css/ 
      ], 
      devDependencies: true 
     })) 
     .pipe(gulp.dest('./')); 
}); 

gulp.task('constant', function() { 
    let sharedConfig = require(`./${serverPath}/config/environment/shared`); 
    return plugins.ngConstant({ 
    name: 'myApp.constants', 
    deps: [], 
    wrap: true, 
    stream: true, 
    constants: { appConfig: sharedConfig } 
    }) 
    .pipe(plugins.rename({ 
     basename: 'app.constant' 
    })) 
    .pipe(gulp.dest(`${clientPath}/app/`)) 
}); 

カルマファイル:私はそれらを実行するタスクの一気使用

// list of files/patterns to load in the browser 
files: [ 
    // bower:js 
    'client/bower_components/jquery/dist/jquery.js', 
    'client/bower_components/angular/angular.js', 
    'client/bower_components/angular-resource/angular-resource.js', 
    'client/bower_components/angular-cookies/angular-cookies.js', 
    'client/bower_components/angular-sanitize/angular-sanitize.js', 
    'client/bower_components/lodash/dist/lodash.compat.js', 
    'client/bower_components/angular-ui-router/release/angular-ui-router.js', 
    'client/bower_components/semantic/dist/semantic.js', 
    'client/bower_components/moment/moment.js', 
    'client/bower_components/angular-moment/angular-moment.js', 
    'client/bower_components/angular-mocks/angular-mocks.js', 
    // endbower 
    'client/app/app.js', 
    'client/{app,components}/**/*.module.js', 
    'client/{app,components}/**/*.js', 
    'client/{app,components}/**/*.{jade,html}' 
], 

ファントムJS "phantomjs-prebuilt": "^2.1.4"

+0

テスト設定を投稿できますか?どのファイルが含まれていますか? – mariocatch

+0

@mariocatchはconfig stuffを追加しました。 –

+0

@ MaximeRoussin-Bélanger:PhantomJSを使用していますか?どのバージョン?カードの指示はどのように見えるのですか(蒸散版)? – gkalpak

答えて

1

を私はとても慣れていジャスミンの、私はチャイ主張の図書館にいたのか分からなかった。

+0

これで問題が解決した場合は、それを受け入れ済みとマークする必要があります(同じ問題に直面している人々が簡単に見つけられるようになります)。 – gkalpak

+0

それであなたはどうやってそれを修正しましたか?あなたの解決策を理解できませんか? – Juri

関連する問題