Ich versuche eine wirklich einfache Direktive mit AngularJS 1.5.5 zu testen.Nicht definiert ist kein Konstruktor, angularjs directional test
Die Richtlinie selbst:
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');
});
}
};
});
Der Test:
'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);
}));
});
Aber mein Test schlägt fehl, da dieser Fehler:
Undefined is not a constructor (evaluating 'expect(element.hasClass('selected')).toBe(true)')
ich bei dieser Frage sah: https://github.com/angular/angular.js/issues/14251 , aber ich benutze die gleiche Version für alle angularjs suite. Was fehlt mir hier?
Mit Schluck für die Aufgabe, die ich laufen sie mit: (schluck Test: Client):
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/`))
});
Karma Dateien:
// 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}'
],
Phantom JS "phantomjs-prebuilt": "^2.1.4"
Können Sie Ihre Testkonfiguration posten? Welche Dateien sind enthalten? – mariocatch
@MarioCatch hinzugefügt Config Zeug, brauchen mehr? –
@ MaximeRoussin-Bélanger: Verwenden Sie PhantomJS? Welche Version? Wie sieht die Karten-Direktive aus (die transpilierte Version)? – gkalpak