useCustomContent.test.ts36 lines · main
1import { cleanup, renderHook } from '@testing-library/react'
2import { beforeEach, describe, expect, it, vi } from 'vitest'
3
4beforeEach(() => {
5 vi.clearAllMocks()
6 vi.resetModules()
7 cleanup()
8})
9
10describe('useCustomContent', () => {
11 it('should return null if content is not found in the custom-content.json file', async () => {
12 vi.doMock('./custom-content.json', () => ({
13 default: {
14 'organization:legal_documents': null,
15 },
16 }))
17
18 const { useCustomContent } = await import('./useCustomContent')
19 const { result } = renderHook(() => useCustomContent(['organization:legal_documents']))
20 expect(result.current.organizationLegalDocuments).toEqual(null)
21 })
22
23 it('should return the content for the key passed in if it exists in the custom-content.json file', async () => {
24 vi.doMock('./custom-content.json', () => ({
25 default: {
26 'organization:legal_documents': {
27 someValue: 'foo',
28 },
29 },
30 }))
31
32 const { useCustomContent } = await import('./useCustomContent')
33 const { result } = renderHook(() => useCustomContent(['organization:legal_documents']))
34 expect(result.current.organizationLegalDocuments).toEqual({ someValue: 'foo' })
35 })
36})