-
Notifications
You must be signed in to change notification settings - Fork 4
Does not react to different request parameters #1
Comments
Hey, sorry I missed this earlier. I'm not sure how you would make things work to have different responses to the same request. The way that I have overcome it in my apps, has been to append an extra parameter to the different requests in test so that I can work with different responses (authentication/create/?username=foo&password=bar&error_test=true) or something like that. |
I should have made it clear I'm doing a POST. Betamax will cache the login fail test and then when supplied correct login details it repeats the failure it has cached for the url. |
Yeah, unfortunately the way things work, it expects all ajax calls to have the same response, depending on what is posted. If you post with different values (different username or password) does it not cache those as different requests? |
Sinon's fake server allows the response to be a function instead of an object. See the |
Yeah, part of the issue is that maybe there should be an option to map calls from a specific test to results. Right now it caches requests that are identical, but this messes with any case where your test might expect two identical requests to return two different results. |
For now, I'm using the Sinon server that Betamax exposes: import { getServer } from '../../helpers/fake-server';
const passwordIsPassword = /^(.*&)?password=password(&.*)?$/;
getServer().respondWith('POST', '/sign-in', function(request) {
if (passwordIsPassword.test(request.requestBody)) {
request.respond(200, {}, JSON.stringify({ user: { id: 8 } }));
} else {
request.respond(403, {}, '');
}
}); |
I've tried using this library but my authentication tests fail since they test the same end point with valid/invalid passwords yet this addon caches the first call to api/session. It would be great if there was a way to configure it to also respect the request parameters.
The text was updated successfully, but these errors were encountered: