https://github.com/martinkr/jquery.ajaxmock
A tiny yet powerful mocking plugin for jQuery 1.5+
https://github.com/martinkr/jquery.ajaxmock
Last synced: 3 months ago
JSON representation
A tiny yet powerful mocking plugin for jQuery 1.5+
- Host: GitHub
- URL: https://github.com/martinkr/jquery.ajaxmock
- Owner: martinkr
- License: other
- Created: 2012-02-26T17:05:22.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2018-07-13T04:51:15.000Z (almost 7 years ago)
- Last Synced: 2025-04-07T19:46:40.818Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 598 KB
- Stars: 19
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE.markdown
Awesome Lists containing this project
README
[jQuery.ajaxMock](https://github.com/martinkr/jQuery.ajaxMock)
=======
jQuery.ajaxMock is a tiny yet powerful mocking plugin for jQuery 1.5+
Just register a fake response (the mock object) . All subsequent $.ajax calls to registered urls will be incercepted, and their're callbacks will recieve the faked response.
Keep in mind that no real XHRrequests will be made.Works like a charm with Jasmine (http://pivotal.github.com/jasmine/) the a behavior-driven development framework for testing JavaScript code.
## Example
Register your mock object:
/*
jQuery.ajaxMock.register( URL , {
reponseText: "{String} Mocked responseText",
statusCode: "{Number} Mocked status code",
status: "{String} Mocked status description",
type: "{String} http request method"
})
*/
jQuery.ajaxMock.register('http://example.com', {
responseText:'responseFoo',
statusCode:200,
status:'OK',
type: 'POST', // optional, takes a String as http request method default: 'GET'
delay: 1000 // optional
})
);
And all $.ajax-calls to 'http://example.com' will return the mocked response.## Requires
* jQuery JavaScript Library 1.5+ - http://jquery.com/; Copyright 2010, John Resig; Dual licensed under the MIT or GPL Version 2 licenses - http://jquery.org/license## License
Dual licensed under the MIT and GPL licenses.* MIT - http://www.opensource.org/licenses/mit-license.php
* GNU - http://www.gnu.org/licenses/gpl-3.0.htmlCopyright (c) 2012 Martin Krause (jquery.public.mkrause.info)