Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for un-mocked calls. #44

Closed
wants to merge 2 commits into from

4 participants

Eric A. Zarko Max Lynch Vic Metcalfe Jonathan Sharp
Eric A. Zarko

I was having an issue where I was trying to mock a somewhat long call which required access to the Internet (so that I could iterate faster and without necessarily having connectivity). There were certain calls, however, that I did not want to mock because they were only hitting my local development instance. They didn't seem to be working properly though. After some debugging this seems to be the answer to the problem. If it is acceptable to you please merge.

ezarko added some commits
Eric A. Zarko ezarko lint fabfdb8
Eric A. Zarko ezarko Fixed un-mocked requests.
The original arguments are url and origSettings.  At the beginning of
the function if url is an object, origSettings is set to url and url is
set to undefined.  In Google Chrome on Mac (at least) this means that
arguments ends up being length 1 with just undefined in it.
1a9b7c2
Vic Metcalfe

Thanks ezarko - I'm adding unit tests to some existing code and working through ajax requests one at a time with mocks. This really helped me out.

Max Lynch

Looks like this was fixed with #48 as well. This can be closed.

Jonathan Sharp jdsharp closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 5, 2011
  1. Eric A. Zarko

    lint

    ezarko authored
  2. Eric A. Zarko

    Fixed un-mocked requests.

    ezarko authored
    The original arguments are url and origSettings.  At the beginning of
    the function if url is an object, origSettings is set to url and url is
    set to undefined.  In Google Chrome on Mac (at least) this means that
    arguments ends up being length 1 with just undefined in it.
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 14 deletions.
  1. +12 −14 jquery.mockjax.js
26 jquery.mockjax.js
View
@@ -27,7 +27,7 @@
}
try {
- var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
+ var xmlDoc = ( new DOMParser() ).parseFromString( xml, 'text/xml' );
if ( $.isXMLDoc( xmlDoc ) ) {
var err = $('parsererror', xmlDoc);
if ( err.length == 1 ) {
@@ -55,7 +55,7 @@
origSettings.url = url;
}
var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings),
- mock = false;
+ mock = false;
// Iterate over our mock handlers (in registration order) until we find
// one that is willing to intercept the request
$.each(mockHandlers, function(k, v) {
@@ -236,9 +236,9 @@
}
m.data = s.data;
- m.cache = s.cache;
- m.timeout = s.timeout;
- m.global = s.global;
+ m.cache = s.cache;
+ m.timeout = s.timeout;
+ m.global = s.global;
mock = _ajax.call($, $.extend(true, {}, origSettings, {
// Mock the XHR object
@@ -260,15 +260,15 @@
open: function() { },
send: function() {
- mockHandlers[k].fired = true;
+ mockHandlers[k].fired = true;
// This is a substitute for < 1.4 which lacks $.proxy
var process = (function(that) {
return function() {
return (function() {
// The request has returned
- this.status = m.status;
- this.readyState = 4;
+ this.status = m.status;
+ this.readyState = 4;
// We have an executable function, call it to give
// the mock handler a chance to update it's data
@@ -289,7 +289,7 @@
this.responseText = m.responseText;
}
if( typeof m.status == 'number' || typeof m.status == 'string' ) {
- this.status = m.status;
+ this.status = m.status;
}
// jQuery < 1.4 doesn't have onreadystate change for xhr
if ( $.isFunction(this.onreadystatechange) ) {
@@ -358,7 +358,7 @@
});
// We don't have a mock request, trigger a normal request
if ( !mock ) {
- return _ajax.apply($, arguments);
+ return _ajax.apply($, [origSettings]);
} else {
return mock;
}
@@ -368,9 +368,7 @@
$.mockjaxSettings = {
//url: null,
//type: 'GET',
- log: function(msg) {
- window['console'] && window.console.log && window.console.log(msg);
- },
+ log: function(msg) {window['console'] && window.console.log && window.console.log(msg);},
status: 200,
responseTime: 500,
isTimeout: false,
@@ -402,7 +400,7 @@
}
};
$.mockjax.handler = function(i) {
- if ( arguments.length == 1 ) {
+ if ( arguments.length == 1 ) {
return mockHandlers[i];
}
};
Something went wrong with that request. Please try again.