Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Possible to respond differently based on order of calls? #9

Closed
anilanar opened this issue May 27, 2018 · 1 comment
Closed

Possible to respond differently based on order of calls? #9

anilanar opened this issue May 27, 2018 · 1 comment

Comments

@anilanar
Copy link
Owner

From moxios created by mrchief : axios#39

Trying to test retry logic of a method, so I've it wired up like this:

    moxios.wait(() => {
      const request = moxios.requests.at(0)
      request.respondWith({
        status: 401
        , response: mockApiError
      })

      const nextRequest = moxios.requests.at(1)
      nextRequest.respondWith({
        status: 200
        , response: mockApiResponse
      })
    })

    const mockRequest = {
      headers: {}
      , method: 'get'
      , url: 'to/no/where'
    }

    const response = await tryMakeRequest(mockRequest)

    expect(response.status).toBe(200)
    expect(response.data).toEqual(mockApiResponse)

The test fails with this error:

    Timeout - Async callback was not invoked within timeout specified by
jasmine.DEFAULT_TIMEOUT_INTERVAL.

      at node_modules/jest-jasmine2/build/queue_runner.js:64:21
      at Timeout.callback [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:523:19)
      at ontimeout (timers.js:469:11)
      at tryOnTimeout (timers.js:304:5)
      at Timer.listOnTimeout (timers.js:264:5)

Any ideas what am I missing here?

@anilanar
Copy link
Owner Author

You need to make your request first without an await. Then use moxios.wait.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant