Skip to content

Instantly share code, notes, and snippets.

@mattdsteele
Last active January 18, 2016 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdsteele/33f9b237fd13e9edc222 to your computer and use it in GitHub Desktop.
Save mattdsteele/33f9b237fd13e9edc222 to your computer and use it in GitHub Desktop.
Angular 1.5.0-rc.1 regression with Karma + PhantomJS

What is this?

A test case that shows Angular 1.5.0-rc.1 unable to execute Karma + Jasmine tests

Relevant files

  • sampleProvider.js - A very simple configurable provider.
  • sampleProvider_spec.js - Some tests for the provider that should give you an idea of how you might test your real provider

Reproduction steps

npm install
npm test

Should see the following error:

PhantomJS 1.9.8 (Windows 7 0.0.0) sampleProvider Default Configuration Should get the default value FAILED
        Error: [$injector:modulerr] Failed to instantiate module ng due to:
        TypeError: 'undefined' is not an object (evaluating 'Function.prototype.bind.apply')
            at instantiate (C:/app/node_modules/angular/angular.js:4622)
module.exports = function(config) {
'use strict';
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-phantomjs-launcher')
],
// list of files / patterns to load in the browser
files: [
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'sampleProvider.js',
'sampleProvider_spec.js'
],
// list of files to exclude
exclude: [],
// 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: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// 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: true
});
};
{
"name": "sampleProvider",
"description": "Shows an example of how you can test your AngularJS providers.",
"version": "1.0.0",
"scripts": {
"test": "karma start karma.conf.js"
},
"dependencies": {
"angular": "1.5.0-rc.1",
"angular-mocks": "1.5.0-rc.1"
},
"devDependencies": {
"jasmine-core": "^2.4.1",
"jasmine-jquery": "^2.1.1",
"karma": "^0.13.11",
"karma-jasmine": "^0.3.6",
"karma-phantomjs-launcher": "^0.2.1",
"phantomjs": "^1.9.19"
},
"engines": {
"node": ">=0.10.0"
}
}
angular
.module('sample', [])
.provider('sample', function() {
'use strict';
var value = 'Default Value';
this.setValue = function(val) {
value = val;
};
this.$get = function() {
var getValue = function() {
return value;
};
var throwValue = function() {
throw new Error(value);
};
return {
getValue: getValue,
throwValue: throwValue
};
};
});
describe('sampleProvider', function() {
'use strict';
// Provider instance
var sample;
// Instanciates the module
beforeEach(function() {
module('sample');
});
// Here we don't do any configuration to our provider
describe('Default Configuration', function() {
beforeEach(function() {
inject(function(_sample_) {
sample = _sample_;
});
});
it('Should get the default value', function() {
expect(sample.getValue()).toBe('Default Value');
});
});
// Here we do some configuration
describe('Configuration A', function() {
// Configure the provider and instanciate it
beforeEach(function() {
module(function(sampleProvider) {
sampleProvider.setValue('A');
});
inject(function(_sample_) {
sample = _sample_;
});
});
it('Should get the configured value', function() {
expect(sample.getValue()).toBe('A');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment