jquery.mockjax.js
function getMockForRequest( handler, requestSettings ) {
		// If the mock was registered with a function, let the function decide if we
		// want to mock this request
		if ( $.isFunction(handler) ) {
			return handler( requestSettings );
		}

		// Inspect the URL of the request and check if the mock handler's url
		// matches the url for this ajax request
		if ( $.isFunction(handler.url.test) ) {
			// The user provided a regex for the url, test it
			if ( !handler.url.test( requestSettings.url ) ) {
				return null;
			}
		} else {
			// Look for a simple wildcard '*' or a direct URL match
			var star = handler.url.indexOf('*');
			if (handler.url !== requestSettings.url && star === -1 ||
					!new RegExp(handler.url.replace(/[-[\]{}()+?.,\\^$|#\s]/g, "\\$&").replace(/\*/g, '.+')).test(requestSettings.url)) {
				return null;
			}
		}

		// Inspect the data submitted in the request (either POST body or GET query string)
		if ( handler.data ) {
			if ( ! requestSettings.data || !isMockDataEqual(handler.data, requestSettings.data) ) {
				// They're not identical, do not mock this request
				return null;
			}
		}
		// Inspect the request type
		if ( handler && handler.type &&
				handler.type.toLowerCase() != requestSettings.type.toLowerCase() ) {
			// The request type doesn't match (GET vs. POST)
			return null;
		}

		return handler;
	}
function getMockForRequest( handler, requestSettings ) {
		// If the mock was registered with a function, let the function decide if we
		// want to mock this request
		if ( $.isFunction(handler) ) {
			return handler( requestSettings );
		}

		// Inspect the URL of the request and check if the mock handler's url
		// matches the url for this ajax request
		if ( $.isFunction(handler.url.test) ) {
			// The user provided a regex for the url, test it
			if ( !handler.url.test( requestSettings.url ) ) {
				return null;
			}
		} else {
			// Look for a simple wildcard '*' or a direct URL match
			var star = handler.url.indexOf('*');
			if (handler.url !== requestSettings.url && star === -1 ||
					!new RegExp(handler.url.replace(/[-[\]{}()+?.,\\^$|#\s]/g, "\\$&").replace(/\*/g, '.+')).test(requestSettings.url)) {
				return null;
			}
		}

		// Inspect the data submitted in the request (either POST body or GET query string)
		if ( handler.data ) {
			if ( ! requestSettings.data || !isMockDataEqual(handler.data, requestSettings.data) ) {
				// They're not identical, do not mock this request
				return null;
			}
		}
		// Inspect the request type
		if ( handler && handler.type &&
				handler.type.toLowerCase() != requestSettings.type.toLowerCase() ) {
			// The request type doesn't match (GET vs. POST)
			return null;
		}

		return handler;
	}
function getMockForRequest ( handler , requestSettings ) { // If the mock was registered with a function, let the function decide if we // want to mock this request if ( $ . isFunction ( handler ) ) { return handler ( requestSettings ) ; } // Inspect the URL of the request and check if the mock handler's url // matches the url for this ajax request if ( $ . isFunction ( handler . url . test ) ) { // The user provided a regex for the url, test it if ( ! handler . url . test ( requestSettings . url ) ) { return null ; } } else { // Look for a simple wildcard '*' or a direct URL match var star = handler . url . indexOf ( '*' ) ; if ( handler . url !== requestSettings . url && star === - 1 || ! new RegExp ( handler . url . replace ( / [-[\]{}()+?.,\\^$|#\s] / g , "\\$&" ) . replace ( / \* / g , '.+' ) ) . test ( requestSettings . url ) ) { return null ; } } // Inspect the data submitted in the request (either POST body or GET query string) if ( handler . data ) { if ( ! requestSettings . data || ! isMockDataEqual ( handler . data , requestSettings . data ) ) { // They're not identical, do not mock this request return null ; } } // Inspect the request type if ( handler && handler . type && handler . type . toLowerCase ( ) != requestSettings . type . toLowerCase ( ) ) { // The request type doesn't match (GET vs. POST) return null ; } return handler ; }
Check the given handler should mock the given request
Check the given handler should mock the given request