|
1 | | -import { renderHook } from '@testing-library/react-hooks/native'; |
| 1 | +import { renderHook } from '@testing-library/react'; |
| 2 | +import { vi, test, expect } from 'vitest'; |
2 | 3 | import FlagProvider from "./FlagProvider"; |
3 | 4 | import { useFlagContext } from "./useFlagContext"; |
4 | 5 |
|
5 | | -test("throws an error if used outside of a FlagProvider", () => { |
| 6 | +test("logs an error if used outside of a FlagProvider", () => { |
| 7 | + const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); |
| 8 | + |
6 | 9 | const { result } = renderHook(() => useFlagContext()); |
| 10 | + expect(consoleSpy).toHaveBeenCalledWith("This hook must be used within a FlagProvider"); |
| 11 | + expect(result.current).toBeNull(); |
7 | 12 |
|
8 | | - expect(result.error).toEqual( |
9 | | - Error("This hook must be used within a FlagProvider") |
10 | | - ); |
| 13 | + consoleSpy.mockRestore(); |
11 | 14 | }); |
12 | 15 |
|
13 | | -test("does not throw an error if used inside of a FlagProvider", () => { |
| 16 | +test("does not log an error if used inside of a FlagProvider", () => { |
| 17 | + const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); |
| 18 | + |
14 | 19 | const { result } = renderHook(() => useFlagContext(), { wrapper: FlagProvider }); |
| 20 | + expect(consoleSpy).not.toHaveBeenCalled(); |
| 21 | + expect(result.current).not.toBeNull(); |
15 | 22 |
|
16 | | - expect(result.error).toBeUndefined(); |
| 23 | + consoleSpy.mockRestore(); |
17 | 24 | }); |
0 commit comments