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",
"devDependencies": {
"connect-livereload": "0.3.1",
"karma-jasmine": "0.1.4",
"karma-jasmine": "0.2.2",
"grunt-contrib-concat": "0.3.0",
"grunt-contrib-copy": "0.4.1",
"grunt-contrib-clean": "0.5.0",

View File

@ -21,8 +21,7 @@
describe('httpErrorBroadcaster', function () {
'use strict';
var $rootScope, $httpBackend, $http, $resource, MockResource,
storyboardApiBase;
var $rootScope, $httpBackend, $resource, MockResource;
var errorResponse = {
error_code: 404,
@ -37,50 +36,30 @@ describe('httpErrorBroadcaster', function () {
inject(function ($injector) {
// Capture various providers for later use.
$rootScope = $injector.get('$rootScope');
$http = $injector.get('$http');
$httpBackend = $injector.get('$httpBackend');
$resource = $injector.get('$resource');
MockResource = $resource('/foo/:id', {id: '@id'});
storyboardApiBase = $injector.get('storyboardApiBase');
});
// Start listening to the broadcast method.
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')
.respond(553, JSON.stringify(errorResponse));
var complete = false;
runs(function () {
MockResource.get({'id': 99},
function () {
complete = true;
},
function () {
complete = true;
});
$httpBackend.flush();
});
waitsFor(function () {
return complete;
}, 'query to complete', 5000);
runs(function () {
// Handle a result.
function handleResult() {
expect($rootScope.$broadcast)
.toHaveBeenCalledWith('http_553', errorResponse);
});
done();
}
MockResource.get({'id': 99}, handleResult, handleResult);
$httpBackend.flush();
});
});