Upgraded jasmine

The Async spec in jasmine was updated, and includes the ability to
register custom matchers. I've upgraded our unit tests to make use
of this new framework.

Change-Id: Id00d29df7e0b41f01f5fe68e1b1d86a224e9505b
This commit is contained in:
Michael Krotscheck 2014-03-28 16:46:03 -07:00
parent 0b1ee74f9e
commit f07bd3b54e
2 changed files with 11 additions and 32 deletions

View File

@ -17,7 +17,7 @@
"license": "Apache2", "license": "Apache2",
"devDependencies": { "devDependencies": {
"connect-livereload": "0.3.1", "connect-livereload": "0.3.1",
"karma-jasmine": "0.1.4", "karma-jasmine": "0.2.2",
"grunt-contrib-concat": "0.3.0", "grunt-contrib-concat": "0.3.0",
"grunt-contrib-copy": "0.4.1", "grunt-contrib-copy": "0.4.1",
"grunt-contrib-clean": "0.5.0", "grunt-contrib-clean": "0.5.0",

View File

@ -21,8 +21,7 @@
describe('httpErrorBroadcaster', function () { describe('httpErrorBroadcaster', function () {
'use strict'; 'use strict';
var $rootScope, $httpBackend, $http, $resource, MockResource, var $rootScope, $httpBackend, $resource, MockResource;
storyboardApiBase;
var errorResponse = { var errorResponse = {
error_code: 404, error_code: 404,
@ -37,50 +36,30 @@ describe('httpErrorBroadcaster', function () {
inject(function ($injector) { inject(function ($injector) {
// Capture various providers for later use. // Capture various providers for later use.
$rootScope = $injector.get('$rootScope'); $rootScope = $injector.get('$rootScope');
$http = $injector.get('$http');
$httpBackend = $injector.get('$httpBackend'); $httpBackend = $injector.get('$httpBackend');
$resource = $injector.get('$resource'); $resource = $injector.get('$resource');
MockResource = $resource('/foo/:id', {id: '@id'}); MockResource = $resource('/foo/:id', {id: '@id'});
storyboardApiBase = $injector.get('storyboardApiBase');
}); });
// Start listening to the broadcast method. // Start listening to the broadcast method.
spyOn($rootScope, '$broadcast'); spyOn($rootScope, '$broadcast');
}); });
// Teardown
afterEach(function () {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
it('should capture events on the $rootScope', function (done) {
it('should capture events on the $rootScope', function () { // Prepare the HTTP Backend
$httpBackend.when('GET', '/foo/99') $httpBackend.when('GET', '/foo/99')
.respond(553, JSON.stringify(errorResponse)); .respond(553, JSON.stringify(errorResponse));
var complete = false; // Handle a result.
function handleResult() {
runs(function () {
MockResource.get({'id': 99},
function () {
complete = true;
},
function () {
complete = true;
});
$httpBackend.flush();
});
waitsFor(function () {
return complete;
}, 'query to complete', 5000);
runs(function () {
expect($rootScope.$broadcast) expect($rootScope.$broadcast)
.toHaveBeenCalledWith('http_553', errorResponse); .toHaveBeenCalledWith('http_553', errorResponse);
}); done();
}
MockResource.get({'id': 99}, handleResult, handleResult);
$httpBackend.flush();
}); });
}); });