New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible to respond differently based on order of calls? #39
Comments
For the time being, I'm using mock.onGet('/to/no/where').replyOnce(401, mockApiError)
.onGet('/to/no/where').replyOnce(200, mockApiResponse) |
Kamino cloned this issue to anilanar/moxios |
Couldn't find a resolution for this. This is how I addressed this issue, if it helps the next poor soul: In this example, the same route fails the first time, then succeeds for subsequent requests. This logic can be expanded to check anything from authentication flow to rate limit // Initial setup
class MockResponse {
constructor() {
this.iterations = 0;
}
get response() {
this.iterations++;
return this.iterations === 1 ? 'Forbidden' : 'Allowed';
}
get status() {
return this.iterations === 1 ? 403 : 200;
}
}
// Register in beforeEach
moxios.stubRequest('/route', new MockResponse());
// First call fails: gets 403
expect(axios.get('/route')).rejects.toThrow('Request failed with status code 404');
// The next one's okay: gets 200
const { status } = await axios.get(REQUEST_PERIMETERX_BLOCK);
expect(status).toBe(200); |
omrilotan, thanks a lot. By the way, as i understand, moxios.stubRequest first calls get response and then get status. |
@veryneatperson You're right Lines 268 to 269 in 3785075
I'll switch them in the comment |
Slightly different take:
|
Trying to test retry logic of a method, so I've it wired up like this:
The test fails with this error:
Any ideas what am I missing here?
The text was updated successfully, but these errors were encountered: