diff --git a/src/index.tsx b/src/index.tsx index 801971b..060bed8 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -7,4 +7,4 @@ export {default as SkipNav} from './SkipNav'; export {default as Tabs, TabContent} from './Tabs'; export {default as UkraineButton} from './UkraineButton'; export {default as useComponentDimensionsWithRef} from './useComponentDimensionsWithRef'; -export {default as usePageTitle} from './usePageTitle'; \ No newline at end of file +export {default as usePageTitle} from './setPageTitle'; \ No newline at end of file diff --git a/src/usePageTitle.test.tsx b/src/setPageTitle.test.tsx similarity index 57% rename from src/usePageTitle.test.tsx rename to src/setPageTitle.test.tsx index dd54cff..dd2ffe0 100644 --- a/src/usePageTitle.test.tsx +++ b/src/setPageTitle.test.tsx @@ -1,31 +1,30 @@ -import {renderHook} from '@testing-library/react'; -import usePageTitle from './usePageTitle'; +import setPageTitle from './setPageTitle'; const siteTitle = 'site name'; -describe('usePageTitle.ts', () => { +describe('setPageTitle.ts', () => { test('set', async () => { const title = 'test title'; - renderHook(() => usePageTitle(title, siteTitle)); + setPageTitle(title, siteTitle); expect(document.title).toBe(`${title} - ${siteTitle}`); }); test('env var based site title', async () => { - const title = 'test title'; + const title = 'test title'; - renderHook(() => usePageTitle(title)); + setPageTitle(title); expect(document.title).toBe(`${title}`); process.env.REACT_APP_MUI_ADDITIONS_SITE_TITLE = 'site title'; - renderHook(() => usePageTitle(title)); + setPageTitle(title); expect(document.title).toBe(`${title} - site title`); }); test('failed set', async () => { const title = test title; - renderHook(() => usePageTitle(String(title), siteTitle)); + setPageTitle(String(title), siteTitle); expect(document.title).toBe(`[object Object] - ${siteTitle}`); }); diff --git a/src/usePageTitle.ts b/src/setPageTitle.ts similarity index 68% rename from src/usePageTitle.ts rename to src/setPageTitle.ts index 650d5f6..a754184 100644 --- a/src/usePageTitle.ts +++ b/src/setPageTitle.ts @@ -1,3 +1,3 @@ -export default function usePageTitle(newTitle: string, siteTitle: string = process.env.REACT_APP_MUI_ADDITIONS_SITE_TITLE || '') { +export default function setPageTitle(newTitle: string, siteTitle: string = process.env.REACT_APP_MUI_ADDITIONS_SITE_TITLE || '') { document.title = `${newTitle}${siteTitle ? ` - ${siteTitle}` : ''}`; } \ No newline at end of file