|
1 | 1 | /*! jQuery Mockjax
|
2 | 2 | * A Plugin providing simple and flexible mocking of ajax requests and responses
|
3 | 3 | *
|
4 |
| - * Version: 2.6.0 |
| 4 | + * Version: 2.7.0-beta.0 |
5 | 5 | * Home: https://github.com/jakerella/jquery-mockjax
|
6 | 6 | * Copyright (c) 2024 Jordan Kasper, formerly appendTo;
|
7 | 7 | * NOTE: This repository was taken over by Jordan Kasper (@jakerella) October, 2014
|
|
78 | 78 | logger.debug( mock, ['Checking mock data against request data', mock, live] );
|
79 | 79 | var identical = true;
|
80 | 80 |
|
81 |
| - if ( $.isFunction(mock) ) { |
| 81 | + if (typeof mock === 'function') { |
82 | 82 | return !!mock(live);
|
83 | 83 | }
|
84 | 84 |
|
85 | 85 | // Test for situations where the data is a querystring (not an object)
|
86 | 86 | if (typeof live === 'string') {
|
87 | 87 | // Querystring may be a regex
|
88 |
| - if ($.isFunction( mock.test )) { |
| 88 | + if (typeof mock.test === 'function') { |
89 | 89 | return mock.test(live);
|
90 | 90 | } else if (typeof mock === 'object') {
|
91 | 91 | live = getQueryParams(live);
|
|
100 | 100 | return identical;
|
101 | 101 | } else {
|
102 | 102 | if ( typeof live[k] === 'object' && live[k] !== null ) {
|
103 |
| - if ( identical && $.isArray( live[k] ) ) { |
104 |
| - identical = $.isArray( mock[k] ) && live[k].length === mock[k].length; |
| 103 | + if ( identical && Array.isArray( live[k] ) ) { |
| 104 | + identical = Array.isArray( mock[k] ) && live[k].length === mock[k].length; |
105 | 105 | }
|
106 | 106 | identical = identical && isMockDataEqual(mock[k], live[k]);
|
107 | 107 | } else {
|
108 |
| - if ( mock[k] && $.isFunction( mock[k].test ) ) { |
| 108 | + if ( mock[k] && typeof mock[k].test === 'function') { |
109 | 109 | identical = identical && mock[k].test(live[k]);
|
110 | 110 | } else {
|
111 | 111 | identical = identical && ( mock[k] === live[k] );
|
|
160 | 160 | function getMockForRequest( handler, requestSettings ) {
|
161 | 161 | // If the mock was registered with a function, let the function decide if we
|
162 | 162 | // want to mock this request
|
163 |
| - if ( $.isFunction(handler) ) { |
| 163 | + if (typeof handler === 'function') { |
164 | 164 | return handler( requestSettings );
|
165 | 165 | }
|
166 | 166 |
|
|
169 | 169 |
|
170 | 170 | // Inspect the URL of the request and check if the mock handler's url
|
171 | 171 | // matches the url for this ajax request
|
172 |
| - if ( $.isFunction(handler.url.test) ) { |
| 172 | + if (typeof handler.url.test === 'function') { |
173 | 173 | // namespace exists prepend handler.url with namespace
|
174 | 174 | if (!!namespace) {
|
175 | 175 | namespace = namespace.replace(/(\/+)$/, '');
|
|
243 | 243 | }
|
244 | 244 |
|
245 | 245 | function parseResponseTimeOpt(responseTime) {
|
246 |
| - if ($.isArray(responseTime) && responseTime.length === 2) { |
| 246 | + if (Array.isArray(responseTime) && responseTime.length === 2) { |
247 | 247 | var min = responseTime[0];
|
248 | 248 | var max = responseTime[1];
|
249 | 249 | if(isPosNum(min) && isPosNum(max)) {
|
|
292 | 292 | this.responseText = mockHandler.responseText;
|
293 | 293 | }
|
294 | 294 |
|
295 |
| - if ($.isArray(mockHandler.status)) { |
| 295 | + if (Array.isArray(mockHandler.status)) { |
296 | 296 | var idxStatus = Math.floor(Math.random() * mockHandler.status.length);
|
297 | 297 | this.status = mockHandler.status[idxStatus];
|
298 | 298 | } else if (typeof mockHandler.status === 'number' || typeof mockHandler.status === 'string') {
|
|
306 | 306 | onReady = this.onload || this.onreadystatechange;
|
307 | 307 |
|
308 | 308 | // jQuery < 1.4 doesn't have onreadystate change for xhr
|
309 |
| - if ( $.isFunction( onReady ) ) { |
| 309 | + if (typeof onReady === 'function') { |
310 | 310 | if( mockHandler.isTimeout) {
|
311 | 311 | this.status = -1;
|
312 | 312 | }
|
|
319 | 319 |
|
320 | 320 | // We have an executable function, call it to give
|
321 | 321 | // the mock handler a chance to update it's data
|
322 |
| - if ( $.isFunction(mockHandler.response) ) { |
| 322 | + if (typeof mockHandler.response === 'function') { |
323 | 323 | // Wait for it to finish
|
324 | 324 | if ( mockHandler.response.length === 2 ) {
|
325 | 325 | mockHandler.response(origSettings, function () {
|
|
495 | 495 | newMock = ($.Deferred) ? (new $.Deferred()) : null;
|
496 | 496 |
|
497 | 497 | // If the response handler on the moock is a function, call it
|
498 |
| - if ( mockHandler.response && $.isFunction(mockHandler.response) ) { |
| 498 | + if ( mockHandler.response && typeof mockHandler.response === 'function' ) { |
499 | 499 |
|
500 | 500 | mockHandler.response(origSettings);
|
501 | 501 |
|
|
545 | 545 |
|
546 | 546 | if ( newMock ) {
|
547 | 547 | try {
|
548 |
| - json = $.parseJSON( mockHandler.responseText ); |
| 548 | + json = JSON.parse( mockHandler.responseText ); |
549 | 549 | } catch (err) { /* just checking... */ }
|
550 | 550 |
|
551 | 551 | newMock.resolveWith( callbackContext, [json || mockHandler.responseText] );
|
|
641 | 641 | overrideCallback = function(action, mockHandler) {
|
642 | 642 | var origHandler = origSettings[action.toLowerCase()];
|
643 | 643 | return function() {
|
644 |
| - if ( $.isFunction(origHandler) ) { |
| 644 | + if (typeof origHandler === 'function') { |
645 | 645 | origHandler.apply(this, [].slice.call(arguments));
|
646 | 646 | }
|
647 | 647 | mockHandler['onAfter' + action]();
|
|
725 | 725 | }
|
726 | 726 |
|
727 | 727 | // Set up onAfter[X] callback functions
|
728 |
| - if ( $.isFunction( mockHandler.onAfterSuccess ) ) { |
| 728 | + if (typeof mockHandler.onAfterSuccess === 'function') { |
729 | 729 | origSettings.success = overrideCallback('Success', mockHandler);
|
730 | 730 | }
|
731 |
| - if ( $.isFunction( mockHandler.onAfterError ) ) { |
| 731 | + if (typeof mockHandler.onAfterError === 'function') { |
732 | 732 | origSettings.error = overrideCallback('Error', mockHandler);
|
733 | 733 | }
|
734 |
| - if ( $.isFunction( mockHandler.onAfterComplete ) ) { |
| 734 | + if (typeof mockHandler.onAfterComplete === 'function') { |
735 | 735 | origSettings.complete = overrideCallback('Complete', mockHandler);
|
736 | 736 | }
|
737 | 737 |
|
|
935 | 935 | */
|
936 | 936 | $.mockjax = function(settings) {
|
937 | 937 | // Multiple mocks.
|
938 |
| - if ( $.isArray(settings) ) { |
| 938 | + if (Array.isArray(settings)) { |
939 | 939 | return $.map(settings, function(s) {
|
940 | 940 | return $.mockjax(s);
|
941 | 941 | });
|
|
0 commit comments