Skip to content

[Error: Nock] Mocking "Random User Generator API" HTTP Requests #2487

Closed Answered by developermau
developermau asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you're right!

    // Mocking the API response: https://randomuser.me/api?results=2
    nock('https://randomuser.me')
      .defaultReplyHeaders({
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': 'Content-Type',
      })
      .get('/api')
      .query({ results: count })
      .reply(200, { results });

Also, I figured out that my hook had an error with the url

// Befor
 const url = `https://randomuser.me/api/?results=${count}`;

// After
 const url = `https://randomuser.me/api?results=${count}`;

Thank you so much @mastermatt!

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mastermatt
Comment options

@developermau
Comment options

Answer selected by developermau
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants