Comments (8)
Hello! Thanks for posting this. I ran the test below and your code works as expected. Can you tell me what version of jQuery and Mockjax you are using? Also what browser are you testing this on?
This is a working test (in QUnit):
QUnit.test('user issue', function(assert) {
var done = assert.async();
$.mockjax({
url: '/api/v1/users',
data: { bat: 'baz', foo: 'bar' },
type: 'GET',
response: function(settings) {
console.log('ajax settings', JSON.stringify( settings ));
this.responseText = JSON.stringify({ res: "bar" });
}
});
$.ajax({
url: '/api/v1/users',
type: 'GET',
dataType : 'json',
data: { foo: 'bar', bat: 'baz' },
success: function(cc) {
console.log('data in success', JSON.stringify(cc));
assert.ok(cc.res);
assert.strictEqual(cc.res, 'bar');
done();
}
});
});
The output I see is:
Running with params: {"jquery":"3.3.1","testFiles":"[\"bugs\"]"}
Running Module: Miscellaneous Bug Tests ................ajax settings {"url":"/api/v1/users","type":"GET","dataType":"json","data":{"foo":"bar","bat":"baz"},"crossDomain":false}
data in success {"res":"bar"}
.
Time: 3221ms, Total: 35, Passed: 35, Failed: 0
from jquery-mockjax.
Hi jakerella, I have encounter the same problem. I used the jquery-mockjax to mock ajax , If I executed the mockjax in src file code, I can get the mock response. But if I executed the mockjax in unit test, I cann't get the mock response.
We used mixed test framework include jest , Qunit, jasmine .
Do you know the reason?
from jquery-mockjax.
I put your example code in my unit test, still no mock response .
from jquery-mockjax.
I think there is something wrong by using it with Jest, but there is no any hint by command "npm run test"
from jquery-mockjax.
Interesting... I have not used it with Jest, so maybe that is the issue. I have used it with both QUnit and Jasmine though. I'm not sure I have the time to dig in any time soon... but I'll try. If you are getting a specific error or something, maybe post that? Also, may be worth posting on StackOverflow with the jest
tag to see if anyone else has seen this.
from jquery-mockjax.
Closing for inactivity. Feel free to reopen if necessary (if there is more information).
from jquery-mockjax.
I am currently running into this. I have the following test:
describe('mockjax', () => {
it('returns', async () => {
$.mockjax({
url: "/api/get",
responseTime: 100, // default: 500
dataType: "json",
data: { action: "all" },
status: 400
});
await $.ajax({
url: '/api/get',
dataType: "json",
data: { action: "all" }
}).always(() => {
console.log("always log");
})
});
});
Which always ends in a timeout:
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
always log
is never logged to console.
If I remove mockjax then always log
is logged to console.
from jquery-mockjax.
@JustinC474 This is a different issue, please open a new issue on GitHub for it!
from jquery-mockjax.
Related Issues (20)
- Update jsdom version
- Switch to chrome headless in tests HOT 1
- JQuery 3.2.1 ajaxSetup not a function HOT 3
- Store ajax response in json file with Mockjax HOT 2
- Mock post request is not replaced when post request occurred. HOT 9
- Add Issue template
- Add PR template
- $.ajax call's success callback receives undefined - jQuery 3.3.1 HOT 2
- only work with jquery2.1.0, not 2.20 and upper HOT 3
- How to solve cross origin request in mockjax proxy URL? HOT 1
- only work with jquery2.1.0, not 2.20 and upper, with example HOT 3
- Add $.mockjax.clear('/someurl') 'clear by url' to README documentation HOT 1
- safety information when using scan owasp 2017 HOT 2
- beforeSend not called when mockjax setup with a function HOT 2
- Issue with capitalization in headers HOT 1
- Setting namespace works only if url is a string (doesn't work for RegExp) HOT 2
- Compatibility with jQuery 3.x HOT 4
- Dynamically Generating Mock Definitions HOT 1
- Test with latest major versions of jQuery
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-mockjax.