Navigation Menu

Skip to content

Commit

Permalink
Don't override a custom status when using proxy data
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Goodale committed Sep 18, 2013
1 parent cc3874b commit ba537f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
17 changes: 14 additions & 3 deletions jquery.mockjax.js
Expand Up @@ -69,7 +69,7 @@
identical = false;
return identical;
} else {
// This will allow to compare Arrays
// This will allow to compare Arrays
if ( typeof live[k] === 'object' && live[k] !== null ) {
identical = identical && isMockDataEqual(mock[k], live[k]);
} else {
Expand All @@ -85,6 +85,11 @@
return identical;
}

// See if a mock handler property matches the default settings
function isDefaultSetting(handler, property) {
return handler[property] === $.mockjaxSettings[property];
}

// Check the given handler should mock the given request
function getMockForRequest( handler, requestSettings ) {
// If the mock was registered with a function, let the function decide if we
Expand Down Expand Up @@ -194,8 +199,14 @@
complete: function(xhr) {
mockHandler.responseXML = xhr.responseXML;
mockHandler.responseText = xhr.responseText;
mockHandler.status = xhr.status;
mockHandler.statusText = xhr.statusText;
// Don't override the handler status/statusText if it's specified by the config
if (isDefaultSetting(mockHandler, 'status')) {
mockHandler.status = xhr.status;
}
if (isDefaultSetting(mockHandler, 'statusText')) {
mockHandler.statusText = xhr.statusText;
}

this.responseTimer = setTimeout(process, mockHandler.responseTime || 0);
}
});
Expand Down
23 changes: 23 additions & 0 deletions test/test.js
Expand Up @@ -1163,6 +1163,29 @@ asyncTest("Preserve responseText inside a response function when using jsonp and

$.mockjaxClear();
});

asyncTest('Custom status when using proxy', function() {
$.mockjax({
url: '/response-callback',
status: 409,
proxy: 'test_proxy.json'
});

$.ajax({
url: '/response-callback',
error: function(){ ok(true, "error callback was called"); },
success: function(json) {
ok( false, "Success should not be called" );
},
complete: function(xhr) {
equals(xhr.status, 409, 'response status matches');
start();
}
});

$.mockjaxClear();
});

/*
var id = $.mockjax({
...
Expand Down

0 comments on commit ba537f3

Please sign in to comment.