Skip to content

Instantly share code, notes, and snippets.

@jdbevan
Last active August 29, 2015 14:27
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 jdbevan/735d552e1e85e95a2584 to your computer and use it in GitHub Desktop.
Save jdbevan/735d552e1e85e95a2584 to your computer and use it in GitHub Desktop.
jasmine-ajax readyState errors
// Karma configuration
// Generated on Mon Aug 10 2015 17:37:50 GMT+0100 (BST)
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine-ajax','jasmine','jasmine-matchers'],
files: [
'test.js',
'node_modules/jquery/tmp/jquery.js'
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['Chrome', 'Firefox'],
singleRun: true
})
}
{
"name": "jasmine-ajax-readyState-errors",
"version": "0.0.1",
"dependencies": {
"jasmine-core": "~2.3.0",
"jquery": "1.7.2",
"karma": "~0.12.31",
"karma-chrome-launcher": "~0.1.8",
"karma-cli": "~0.0.4",
"karma-firefox-launcher": "~0.1.4",
"karma-jasmine": "~0.3.5",
"karma-jasmine-ajax": "0.1.12",
"karma-jasmine-matchers": "~2.0.0-beta1"
},
"repository": {
"type": "git",
"url": "http://example.com"
}
}
describe("ajax readyState on failure", function() {
beforeEach(function() {
jasmine.Ajax.install();
jasmine.clock().install();
});
afterEach(function() {
jasmine.Ajax.uninstall();
jasmine.clock().uninstall();
});
it("should be 4 when a non-abort error occurs", function(done) {
var readyState = -1;
$.ajax({
url: "http://example.com"
}).done(function() {
// do nothing
}).fail(function(jqXHR, textStatus, error) {
readyState = jqXHR.readyState;
expect(jqXHR.readyState).toBe(4);
}).complete(function() {
expect(readyState).toBe(4);
done();
});
jasmine.Ajax.requests.mostRecent().responseError();
});
it("should be 4 when a non-abort timeout occurs", function(done) {
var readyState = -1;
$.ajax({
url: "http://example.com",
timeout: 5000
}).done(function() {
// do nothing
}).fail(function(jqXHR, textStatus, error) {
readyState = jqXHR.readyState;
expect(jqXHR.readyState).toBe(4);
}).complete(function() {
expect(readyState).toBe(4);
done();
});
jasmine.Ajax.requests.mostRecent().responseTimeout();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment