Skip to content

Commit

Permalink
fix(tests): switch back to Jasmine for IE8 support
Browse files Browse the repository at this point in the history
Finally SauceLabs work as intended, and it showed that ApiMock fails on
IE8. So IE8 is still turned off in SauceLabs config for now.
  • Loading branch information
seriema committed Aug 8, 2015
1 parent 925929b commit 6338b69
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion karma.conf.js
Expand Up @@ -15,7 +15,7 @@ module.exports = function(config) {
basePath: '',

// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['mocha', 'chai'],
frameworks: ['jasmine'],

// reporter style
reporters: [ 'progress' ],
Expand Down
7 changes: 3 additions & 4 deletions package.json
Expand Up @@ -11,7 +11,6 @@
"license": "MIT",
"dependencies": {},
"devDependencies": {
"chai": "^3.2.0",
"grunt": "^0.4.5",
"grunt-bump": "^0.3.0",
"grunt-contrib-clean": "^0.6.0",
Expand All @@ -26,22 +25,22 @@
"grunt-newer": "^1.1.0",
"grunt-ng-annotate": "^1.0.1",
"grunt-nuget": "^0.1.3",
"jasmine": "^2.3.2",
"jasmine-core": "^2.3.4",
"jshint-stylish": "^2.0.1",
"karma-chai": "^0.1.0",
"karma-coffee-preprocessor": "^0.3.0",
"karma": "^0.13.4",
"karma-coverage": "^0.5.0",
"karma-firefox-launcher": "^0.1.3",
"karma-html2js-preprocessor": "~0.1.0",
"karma-mocha": "^0.2.0",
"karma-jasmine": "^0.3.6",
"karma-ng-html2js-preprocessor": "~0.1.0",
"karma-ng-scenario": "~0.1.0",
"karma-phantomjs-launcher": "^0.2.0",
"karma-requirejs": "~0.2.0",
"karma-sauce-launcher": "^0.2.14",
"karma-script-launcher": "~0.1.0",
"load-grunt-tasks": "^3.1.0",
"mocha": "^2.2.1",
"phantomjs": "^1.9.17",
"requirejs": "~2.1.9",
"time-grunt": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion test/.jshintrc
Expand Up @@ -30,8 +30,8 @@
"expect": false,
"inject": false,
"it": false,
"fail": false,
"jasmine": false,
"spyOn": false
}
}

47 changes: 21 additions & 26 deletions test/spec/services/angular-apimock.js
Expand Up @@ -84,42 +84,37 @@ describe('Service: apiMock', function () {
defaultExpectPath = defaultApiPath;
}

function expectHttpFailure(done, fail) {
function expectHttpFailure(doneCb, failCb) {
$httpBackend.expect(defaultExpectMethod, defaultExpectPath).respond(404);

$http(defaultRequest)
.success(function () {
assertFail(); // Todo: How to fail the test if this happens?
fail && fail();
fail(); // Todo: How to fail the test if this happens?
failCb && failCb();
})
.error(function (data, status) {
done && done(data, status);
doneCb && doneCb(data, status);
});

$rootScope.$digest();
$httpBackend.flush();
}

function expectHttpSuccess(done, fail) {
function expectHttpSuccess(doneCb, failCb) {
$httpBackend.expect(defaultExpectMethod, defaultExpectPath).respond({});
$http(defaultRequest)
.success(function () {
done && done();
doneCb && doneCb();
})
.error(function () {
assertFail();
fail && fail();
fail();
failCb && failCb();
});

$rootScope.$digest();
$httpBackend.flush();
}

function assertFail() {
expect(true).to.be.false; // Todo: How to fail properly? There should be a method for that.
}



describe('URL flag', function () {

Expand Down Expand Up @@ -206,7 +201,7 @@ describe('Service: apiMock', function () {
$httpBackend.expect('GET', defaultApiPath).respond(404);

expectHttpSuccess(function() {
expect(apiMock._countFallbacks()).to.equal(0);
expect(apiMock._countFallbacks()).toEqual(0);
});
});

Expand Down Expand Up @@ -242,10 +237,10 @@ describe('Service: apiMock', function () {

// Cannot use $http.expect() because HTTP status doesn't do a request
$http(defaultRequest)
.success(assertFail)
.success(fail)
.error(function(data, status) {
expect(apiMock._countFallbacks()).to.equal(0);
expect(status).to.equal(option);
expect(apiMock._countFallbacks()).toEqual(0);
expect(status).toEqual(option);
});

$rootScope.$digest();
Expand All @@ -255,12 +250,12 @@ describe('Service: apiMock', function () {
it('should have basic header data in $http request status override', function () {
// Cannot use $http.expect() because HTTP status doesn't do a request
$http(defaultRequest)
.success(assertFail)
.success(fail)
.error(function(data, status, headers) {
expect(apiMock._countFallbacks()).to.equal(0);
expect(headers).to.exist;
expect(headers['Content-Type']).to.equal('text/html; charset=utf-8');
expect(headers.Server).to.equal('Angular ApiMock');
expect(apiMock._countFallbacks()).toEqual(0);
expect(headers).toExist;
expect(headers['Content-Type']).toEqual('text/html; charset=utf-8');
expect(headers.Server).toEqual('Angular ApiMock');
});

$rootScope.$digest();
Expand Down Expand Up @@ -503,7 +498,7 @@ describe('Service: apiMock', function () {
setGlobalCommand(true);

expectHttpSuccess(function () {
expect($log.info.logs[0][0]).to.equal('apiMock: rerouting ' + defaultApiPath + ' to ' + defaultMockPath);
expect($log.info.logs[0][0]).toEqual('apiMock: rerouting ' + defaultApiPath + ' to ' + defaultMockPath);
});

unsetGlobalCommand();
Expand All @@ -514,7 +509,7 @@ describe('Service: apiMock', function () {

$httpBackend.expect(defaultRequest.method, defaultApiPath).respond(404);
expectHttpSuccess(function () {
expect($log.info.logs[0][0]).to.equal('apiMock: recovering from failure at ' + defaultApiPath);
expect($log.info.logs[0][0]).toEqual('apiMock: recovering from failure at ' + defaultApiPath);
});

unsetGlobalCommand();
Expand All @@ -526,9 +521,9 @@ describe('Service: apiMock', function () {
// Don't do $httpBackend.expect() because the command doesn't do a real request.
$http(defaultRequest)
.error(function () {
expect($log.info.logs[0][0]).to.equal('apiMock: mocking HTTP status to 404');
expect($log.info.logs[0][0]).toEqual('apiMock: mocking HTTP status to 404');
})
.success(assertFail);
.success(fail);

$rootScope.$digest();
unsetGlobalCommand();
Expand Down

0 comments on commit 6338b69

Please sign in to comment.