Skip to content
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

Mock redaxios with vi.mock() #99

Open
Ismael237 opened this issue May 14, 2024 · 0 comments
Open

Mock redaxios with vi.mock() #99

Ismael237 opened this issue May 14, 2024 · 0 comments

Comments

@Ismael237
Copy link

Ismael237 commented May 14, 2024

How to Mock redaxios like in this code

import { beforeEach, describe, expect, test, vi } from 'vitest'
import { createUser, fetchUsers } from './users.service'
import axios from 'axios'

vi.mock('axios')

describe('Users Service', () => {
  describe('fetchUsers', () => {
    test('makes a GET request to fetch users', async () => {
      const usersMock = [{ id: 1 }, { id: 2 }]

      axios.get.mockResolvedValue({
        data: usersMock,
      })
    })
  })
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant