Skip to content

Commit

Permalink
fix: Flowbite test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Sutu committed Sep 25, 2023
1 parent f423a5b commit 72c6829
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions src/components/Flowbite/Flowbite.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
// TODO: fix test

import { act, render } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { Flowbite, useTheme } from '../../';
import { useThemeMode } from '~/src/helpers/use-theme-mode';
import { getTheme } from '~/src/theme-store';
import { Flowbite } from '../../';
import { mergeDeep } from '../../helpers/merge-deep';
import type { ThemeContextProps } from './ThemeContext';

describe('Components / Flowbite', () => {
describe('hook / useTheme', () => {
it('should return default values', () => {
render(<TestComponent />);

const { theme, mode, toggleMode } = context;

expect(theme).toEqual(theme);
expect(mode).toBeUndefined();
expect(toggleMode).toBeUndefined();
});
});

describe('Flowbite', () => {
it('should return default values', () => {
render(
Expand All @@ -27,8 +14,8 @@ describe('Components / Flowbite', () => {
</Flowbite>,
);

const { theme, mode, toggleMode } = context;
expect(theme).toEqual(theme);
const { mode, toggleMode } = themeMode;

expect(mode).toBe('light');
expect(toggleMode).not.toBeUndefined();
});
Expand All @@ -40,7 +27,7 @@ describe('Components / Flowbite', () => {
</Flowbite>,
);

const { theme } = context;
const theme = getTheme();
const mergedTheme = mergeDeep(theme, customTheme);

expect(theme).toEqual(mergedTheme);
Expand All @@ -53,7 +40,7 @@ describe('Components / Flowbite', () => {
</Flowbite>,
);

const { mode, toggleMode } = context;
const { mode, toggleMode } = themeMode;

expect(mode).toBe('light');
expect(documentEl()).not.toHaveClass('dark');
Expand All @@ -62,7 +49,7 @@ describe('Components / Flowbite', () => {
if (toggleMode) toggleMode();
});

const { mode: mode2 } = context;
const { mode: mode2 } = themeMode;

expect(mode2).toBe('dark');
expect(documentEl()).toHaveClass('dark');
Expand All @@ -75,17 +62,18 @@ describe('Components / Flowbite', () => {
</Flowbite>,
);

const { mode } = context;
const { mode } = themeMode;

expect(mode).toBe('dark');
expect(documentEl()).toHaveClass('dark');
});
});
});

let context: ThemeContextProps;
let themeMode: ReturnType<typeof useThemeMode>;

const TestComponent = () => {
context = useTheme();
themeMode = useThemeMode();
return null;
};

Expand Down

0 comments on commit 72c6829

Please sign in to comment.