Skip to content

Can't test asynchronous functions inside an action #1880

Discussion options

You must be logged in to vote

If this has happened to any of you as well, the solution is quite simple.

  1. Remove this, only use if you have parameters
    { delayResponse: 1000 }

  2. Create a helper that receives the mock from the axios instance and then call it in your component or wherever you need to do it.

const getMockToken = (mock: any) => {
  mock.onGet('/car/tarifier.getSPAToken/').reply(200, {
    success: true,
    token: 'baf25d48-34ea-3a94-aff9-88caafea25b8',
    expires_in: '813',
    message: 'OK'
  })
}

export default getMockToken

In my case I have done it this way for the tokens and to use 3 instances at a time.. like this

const vehicleMocks = () => {
  http.defaults.baseURL = import.meta.env.SOME_ENV
  c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by elalekey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant