Created
February 19, 2016 17:44
-
-
Save Kikketer/1646eccdaff76944b358 to your computer and use it in GitHub Desktop.
Babel + Angular 1 + Promises not resolving
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reference: http://karma-runner.github.io/0.12/config/configuration-file.html | |
module.exports = function karmaConfig (config) { | |
config.set({ | |
frameworks : [ | |
// Reference: https://github.com/karma-runner/karma-jasmine | |
// Set framework to jasmine | |
'jasmine' | |
], | |
reporters : [ | |
// Reference: https://github.com/mlex/karma-spec-reporter | |
// Set reporter to print detailed results to console | |
'progress', | |
// Reference: https://github.com/karma-runner/karma-coverage | |
// Output code coverage files | |
'coverage' | |
], | |
files : [ | |
// Add the polyfill manually (THIS MAY BE THE ISSUE? Couldn't get Promise to work any other way) | |
'node_modules/babel-polyfill/dist/polyfill.min.js', | |
// Grab all files in the app folder that contain .spec. | |
'src/tests.webpack.js' | |
], | |
preprocessors : { | |
// Reference: http://webpack.github.io/docs/testing.html | |
// Reference: https://github.com/webpack/karma-webpack | |
// Convert files with webpack and load sourcemaps | |
'src/tests.webpack.js' : ['webpack', 'babel'] | |
}, | |
browsers : [ | |
// Run tests using PhantomJS2 | |
'PhantomJS' | |
], | |
singleRun : true, | |
// Configure code coverage reporter | |
coverageReporter : { | |
dir : 'coverage/', | |
reporters : [ | |
{type : 'text-summary'}, | |
{type : 'html'} | |
] | |
}, | |
webpack : require('./webpack.unit-test.config'), | |
babelPreprocessor: { | |
options: { | |
presets: ['es2015'], | |
sourceMap: 'inline' | |
} | |
}, | |
// Hide webpack build information from output | |
webpackMiddleware : { | |
noInfo : true | |
}, | |
plugins: [ | |
require('karma-webpack'), | |
require('karma-jasmine'), | |
require('karma-phantomjs-launcher'), | |
require('karma-coverage'), | |
require('karma-spec-reporter'), | |
require('karma-babel-preprocessor') | |
] | |
}); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lots of setup up here | |
// Removed for brevity | |
it('should get an individual project', function () { | |
let response; | |
// mockProject is just a simple JSON object | |
httpBackend.expectGET('projects/' + mockProject.id).respond(mockProject); | |
// Just a test to see if promise doesn't throw an error as a variable | |
new Promise((resolve, reject) => { | |
resolve(); | |
}) | |
.then(() => { | |
// This is never fired | |
console.log('resolved test'); | |
}); | |
// Now actually call it | |
projectsService.getProject(mockProject.id) | |
.then((project) => { | |
// This is NEVER fired | |
console.log('promise resolved!'); | |
response = project; | |
}); | |
// Now we have to flush that http request | |
httpBackend.flush(); | |
// Run the expect... this is always failing since response is empty | |
expect(response).toEqual(mockProject); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I've included this file just to show nothing fancy happening here. | |
// This is the main file that the karma.conf is bringing in (Besides the polyfill) | |
import 'angular'; | |
import 'angular-mocks/angular-mocks'; | |
// I tried to: | |
// import 'babel-polyfill' | |
// but I got a global._babelPolyfill error (window doesn't exist?) | |
var testsContext = require.context(".", true, /.spec$/); | |
console.log(testsContext); | |
testsContext.keys().forEach(testsContext); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment