DRFR0ST / bun-bagel

🥯 The Bun fetch mocker with a hole lot of flavor.
MIT License
17 stars 5 forks source link

`clearMocks` clears mocks once and forever #2

Closed SpeCT closed 3 months ago

SpeCT commented 3 months ago

You can only clear mocks once. Every "mocked" request after that will use real fetch.

describe('Auth API', () => {
  afterEach(() => {
    clearMocks()
  })

  test('GET foo', async () => {
    mock('https://example.com/', { data: { name: 'Foo' } })
    await fetch('https://example.com/')
    expect(res.status).toBe(200) // <<- OK
  })

  test('GET foo', async () => {
    mock('https://example.com/', { data: { name: 'Bar' } })
    await fetch('https://example.com/')
    expect(res.status).toBe(200) // <<- INTERNET
  })
})
DRFR0ST commented 3 months ago

Thanks for the contribution @SpeCT 🚀 Your PRs has been merged and are included in the 1.0.9 release.