Yuki Takei 5 месяцев назад
Родитель
Сommit
920e5c6236
1 измененных файлов с 13 добавлено и 9 удалено
  1. 13 9
      apps/app/src/client/components/TemplateModal/use-formatter.spec.tsx

+ 13 - 9
apps/app/src/client/components/TemplateModal/use-formatter.spec.tsx

@@ -1,13 +1,15 @@
+import { renderHook } from '@testing-library/react';
+
 import { useFormatter } from './use-formatter';
 
 
 const mocks = vi.hoisted(() => {
   return {
-    useCurrentPagePathMock: vi.fn(() => { return {} }),
+    useCurrentPagePathMock: vi.fn<() => string | undefined>(() => undefined),
   };
 });
 
-vi.mock('~/stores/page', () => {
+vi.mock('~/states/page', () => {
   return { useCurrentPagePath: mocks.useCurrentPagePathMock };
 });
 
@@ -24,7 +26,8 @@ describe('useFormatter', () => {
       vi.doMock('mustache', () => mastacheMock);
 
       // when
-      const { format } = useFormatter();
+      const { result } = renderHook(() => useFormatter());
+      const { format } = result.current;
       // call with undefined
       const markdown = format(undefined);
 
@@ -43,7 +46,8 @@ describe('useFormatter', () => {
     vi.doMock('mustache', () => mastacheMock);
 
     // when
-    const { format } = useFormatter();
+    const { result } = renderHook(() => useFormatter());
+    const { format } = result.current;
     const markdown = 'markdown body';
     const formatted = format(markdown);
 
@@ -53,7 +57,8 @@ describe('useFormatter', () => {
 
   it('returns markdown formatted when currentPagePath is undefined', () => {
     // when
-    const { format } = useFormatter();
+    const { result } = renderHook(() => useFormatter());
+    const { format } = result.current;
     const markdown = `
 title: {{{title}}}{{^title}}(empty){{/title}}
 path: {{{path}}}
@@ -69,14 +74,13 @@ path: /
 
   it('returns markdown formatted', () => {
     // setup
-    mocks.useCurrentPagePathMock.mockImplementation(() => {
-      return { data: '/Sandbox' };
-    });
+    mocks.useCurrentPagePathMock.mockReturnValue('/Sandbox');
     // 2023/5/31 15:01:xx
     vi.setSystemTime(new Date(2023, 4, 31, 15, 1));
 
     // when
-    const { format } = useFormatter();
+    const { result } = renderHook(() => useFormatter());
+    const { format } = result.current;
     const markdown = `
 title: {{{title}}}
 path: {{{path}}}