Karma loads tests using RequireJS, but actual specifications don't work

I have a problem when I try to get a Karma runner to fulfill my mocha specifications downloaded with RequireJS. Unfortunately, I cannot understand why the specifications will not be executed, even if the structure is loading. Hope this will be the bit I hope:

// karma.conf.js // Karma configuration // Generated on Thu Jun 13 2013 13:38:06 GMT-0500 (CDT) // base path, that will be used to resolve files and exclude basePath = ''; // list of files / patterns to load in the browser files = [ MOCHA, MOCHA_ADAPTER, REQUIRE, REQUIRE_ADAPTER, // !! libs required for test framework {pattern: 'test/lib/chai.js', included: false}, // !! put what used to be in your requirejs 'shim' config here 'app/bower_components/angular/angular.js', 'app/bower_components/angular-cookies/angular-cookies.js', 'app/bower_components/angular-mocks/angular-mocks.js', 'app/bower_components/angular-resource/angular-resource.js', 'app/bower_components/angular-sanitize/angular-sanitize.js', 'app/bower_components/angular-scenario/angular-scenario.js', 'app/bower_components/jquery/jquery.js', {pattern: 'app/scripts/**/*.js', included: false}, {pattern: 'test/**/*Spec.js', included: false}, 'test/test-main.js' ]; // list of files to exclude exclude = [ 'app/scripts/main.js' ]; // test results reporter to use // possible values: 'dots', 'progress', 'junit' reporters = ['progress']; // web server port port = 9876; // cli runner port runnerPort = 9100; // enable / disable colors in the output (reporters and logs) colors = true; // level of logging // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG logLevel = LOG_INFO; // enable / disable watching file and executing tests whenever any file changes autoWatch = true; browsers = ['Chrome']; // If browser does not capture in given timeout [ms], kill it captureTimeout = 60000; // Continuous Integration mode // if true, it capture browsers, run tests and exit singleRun = false; 

Then this is my test-main.js file that handles requireJS loading

 var tests = []; for (var file in window.__karma__.files) { if (/Spec\.js$/.test(file)) { tests.push('../../' + file.replace(/^\/base\//, '').replace(/\.js$/, '')); } } requirejs.config({ baseUrl: '/base/app/scripts/', paths: { chai: "../../test/lib/chai", namespace: "vendor/namespace", jquery: "../bower_components/jquery/jquery", bootstrap: "vendor/bootstrap", angular: "../bower_components/angular/angular", angularCookies: "../bower_components/angular-cookies/angular-cookies", angularResource: "../bower_components/angular-resource/angular-resource", angularSanitize: "../bower_components/angular-sanitize/angular-sanitize", applicationController: "controllers/application", gameController: "controllers/game", gamePresenter: "directives/game-presenter", } }); require(tests, function(){ window.__karma__.start(); }); 

This is an example of my specification that I am running:

 define(['chai', 'namespace','racecar'], function(chai, namespace, racecar) { var assert = chai.assert, expect = chai.expect, should = chai.should(); // This executes correctly! var player = new com.angular.racecar.Player(); player.should.be.an('object'); // This never gets run! describe('Player', function () { it('should be an object', function () { var player = new com.angular.racecar.Player(); player.should.be.an('object'); }); }); }); 

Here is an example of the code I'm testing:

 (function() { "use strict"; var Player; namespace('com.angular.racecar', { Player: Player = (function() { function Player() { this.car = new com.angular.racecar.Car(); return this; } return Player; })() }); }(this) 

The conclusion simply says:

 INFO [Chrome 27.0 (Mac)]: Connected on socket id fc4Kj9T0ppIzp9D0kmdH Chrome 27.0 (Mac): Executed 0 of 0 SUCCESS (0.192 secs / 0 secs) 
+4
source share
2 answers

Angular-mock should only work with Jasmine. To make it work with Mocha, you need to use the modified angular moment created by http://www.yearofmoo.com/ described in their test article. Direct link to the file https://github.com/yearofmoo-articles/AngularJS-Testing-Article/tree/master/test/lib/angular

0
source

To use mocha tests, you need to use the unstable branch of angular JS and in this> = v1.1.1

You can see that they added mocha support here: https://github.com/angular/angular.js/blob/master/CHANGELOG.md#111-pathological-kerning-2012-11-11-26

Diff: https://github.com/angular/angular.js/commit/92558fe4119fb1ee793d781de1888abef181c7f6

0
source

Source: https://habr.com/ru/post/1486155/


All Articles