{"action":"created","issue":{"url":"https://api.github.com/repos/jakerella/jquery-mockjax/issues/219","labels_url":"https://api.github.com/repos/jakerella/jquery-mockjax/issues/219/labels{/name}","comments_url":"https://api.github.com/repos/jakerella/jquery-mockjax/issues/219/comments","events_url":"https://api.github.com/repos/jakerella/jquery-mockjax/issues/219/events","html_url":"https://github.com/jakerella/jquery-mockjax/issues/219","id":54017429,"number":219,"title":"MockJAX does not work with  CasperJS","user":{"login":"preethiajay","id":10492709,"avatar_url":"https://avatars.githubusercontent.com/u/10492709?v=3","gravatar_id":"","url":"https://api.github.com/users/preethiajay","html_url":"https://github.com/preethiajay","followers_url":"https://api.github.com/users/preethiajay/followers","following_url":"https://api.github.com/users/preethiajay/following{/other_user}","gists_url":"https://api.github.com/users/preethiajay/gists{/gist_id}","starred_url":"https://api.github.com/users/preethiajay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/preethiajay/subscriptions","organizations_url":"https://api.github.com/users/preethiajay/orgs","repos_url":"https://api.github.com/users/preethiajay/repos","events_url":"https://api.github.com/users/preethiajay/events{/privacy}","received_events_url":"https://api.github.com/users/preethiajay/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jakerella/jquery-mockjax/labels/More+Info","name":"More Info","color":"ededed"},{"url":"https://api.github.com/repos/jakerella/jquery-mockjax/labels/quesion","name":"quesion","color":"e1e1e1"},{"url":"https://api.github.com/repos/jakerella/jquery-mockjax/labels/Userspace","name":"Userspace","color":"DDDDDD"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-01-12T03:22:32Z","updated_at":"2015-01-15T13:22:09Z","closed_at":null,"body":"Below is my code which uses casperjs and mockjax . However , mockjax is not able to intercept the ajax call . It returns the ajax response instead of the mock response . Also, $.mockjax.mockedAjaxCalls().length this does not print anything . Any idea what I am doing here?\r\n\r\n```js\r\nvar casper = require(\"casper\").create({\r\n    verbose: true,\r\n    logLevel: 'error',\r\n    clientScripts: [\"jquery.mockjax.js\", \"jquery.js\", \"json2.js\"]\r\n});\r\n\r\ncasper.on('remote.message', function(msg) {\r\n    this.echo('remote message caught: ' + msg);\r\n})\r\n\r\ncasper.start('http://xyz:9000/abc', function() {\r\n    this.evaluate(function() {\r\n        this.capture('1.png')\r\n        $.mockjax({\r\n            url: '/foo1',\r\n            responseTime: 100,\r\n            dataType: 'json',\r\n            responseText: {\r\n                sessionTimeoutRedirectUrl: \"https://foo/hello\",\r\n                errorCode: \"error.session.timeout\"\r\n            }\r\n        });\r\n    });\r\n    this.capture('xyz123.png');\r\n});\r\n\r\n\r\ncasper.waitForSelector('#order-wrapper', function() {\r\n    this.click('#method-field-cc');\r\n    this.capture('mock2.png');\r\n});\r\ncasper.waitForSelector('#cc-card-number', function() {\r\n\r\n    this.capture('mock.png');\r\n    this.fillSelectors('form[id=\"cc-form\"]', {\r\n        'input[id=\"cc-card-number\"]': '4112344112344113',\r\n        'input[id=\"cc-first-name\"]': 'first',\r\n        'input[id=\"cc-last-name\"]': 'last',\r\n        'select[id=\"cc-expiry-month\"]': '10',\r\n        'select[id=\"cc-expiry-year\"]': '2016',\r\n        'input[id=\"tax-field-postal-code\"]': '95051',\r\n        'input[id=\"cc-security-code\"]': '123'\r\n    }, true);\r\n    this.click('#review-newcc');\r\n    this.capture('mock3.png');\r\n\r\n});\r\n\r\ncasper.wait(1000, function() {\r\n    this.echo(\"I've waited for a second.\");\r\n    casper.evaluate(function() {\r\n        this.echo(\"I've waited for a second.\" + $.mockjax.mockedAjaxCalls().length)\r\n        console.log($.mockjax.mockedAjaxCalls());\r\n    });\r\n\r\n\r\n});\r\ncasper.evaluate(function() {\r\n    this.echo(\"I've waited for a second.\" + $.mockjax.mockedAjaxCalls().length)\r\n});\r\ncasper.wait(1000, function() {\r\n    this.capture('mock4.png')\r\n\r\n});\r\n\r\ncasper.run();\r\n```"},"comment":{"url":"https://api.github.com/repos/jakerella/jquery-mockjax/issues/comments/70084397","html_url":"https://github.com/jakerella/jquery-mockjax/issues/219#issuecomment-70084397","issue_url":"https://api.github.com/repos/jakerella/jquery-mockjax/issues/219","id":70084397,"user":{"login":"jakerella","id":450036,"avatar_url":"https://avatars.githubusercontent.com/u/450036?v=3","gravatar_id":"","url":"https://api.github.com/users/jakerella","html_url":"https://github.com/jakerella","followers_url":"https://api.github.com/users/jakerella/followers","following_url":"https://api.github.com/users/jakerella/following{/other_user}","gists_url":"https://api.github.com/users/jakerella/gists{/gist_id}","starred_url":"https://api.github.com/users/jakerella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jakerella/subscriptions","organizations_url":"https://api.github.com/users/jakerella/orgs","repos_url":"https://api.github.com/users/jakerella/repos","events_url":"https://api.github.com/users/jakerella/events{/privacy}","received_events_url":"https://api.github.com/users/jakerella/received_events","type":"User","site_admin":false},"created_at":"2015-01-15T13:22:09Z","updated_at":"2015-01-15T13:22:09Z","body":"@preethiajay Unfortunately you're still not giving us the information we need to debug this issue. However, the fact that you see `MOCK POST: /payments/purchase/taxcartwithnewcc [object Object]` in the console means that Mockjax **is intercepting that ajax call**. So now the question becomes: is that the correct call you want mocked? And if so, is it returning the mock data you expect?\r\n\r\nI think maybe if you understood slightly better what's happening under the covers you might see why we've been asking you for more information. Mockjax is actually quite simple, we alias the `$.ajax()` function to `$._ajax()` and then create our own wrapper function. This let's us inspect the options sent by your code to `$.ajax()` _before_ Mockjax decides whether to use the \"real\" ajax method or just pass back a mock.\r\n\r\nHere's some pseudo code of what that looks like:\r\n\r\n```javascript\r\n// Inside Mockjax (sort of)\r\n\r\n$._ajax = $.ajax;  // aliasing the \"real\" method\r\n\r\n$.ajax = function(options) {\r\n    if (all options match a mock setup) {\r\n        // now we use mock data\r\n    } else {\r\n        // otherwise call the \"real\" ajax method\r\n        $.ajax(options);\r\n    }\r\n};\r\n```\r\n\r\nBecause we inspect all of the options into the `$.ajax()` method to see if they match we **must** see your actual options into both `$.mockjax()` and `$.ajax()` (or in your case, maybe `$.post()`) in order to debug this. If you have sensitive information then you can change the URL or data being POSTed, but we need to see everything inside `$.post(url, data)` as well as all settings you pass into `$.mockjax()`."}}