useCustomContent.test.ts 1.2 KB

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