use-formatter.spec.tsx 751 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { useFormatter } from './use-formatter';
  2. const mocks = vi.hoisted(() => {
  3. return {
  4. useCurrentPagePathMock: vi.fn(() => { return {} }),
  5. };
  6. });
  7. vi.mock('~/stores/page', () => {
  8. return { useCurrentPagePath: mocks.useCurrentPagePathMock };
  9. });
  10. describe('useFormatter', () => {
  11. describe('format()', () => {
  12. it('returns an empty string when the argument is undefined', () => {
  13. // setup
  14. const mastacheMock = {
  15. render: vi.fn(),
  16. };
  17. vi.doMock('mustache', () => mastacheMock);
  18. // when
  19. const { format } = useFormatter();
  20. const markdown = format(undefined);
  21. // then
  22. expect(markdown).toBe('');
  23. expect(mastacheMock.render).not.toHaveBeenCalled();
  24. });
  25. });
  26. });