Skip to content

Commit

Permalink
Merge branch 'frontend-fix-amount-test'
Browse files Browse the repository at this point in the history
  • Loading branch information
shonsirsha committed Oct 16, 2024
2 parents 052e50a + cc9fb57 commit 750aae2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion frontends/web/src/components/amount/amount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { useContext } from 'react';
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { Mock, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { render } from '@testing-library/react';
import { Amount } from './amount';
import { CoinUnit, ConversionUnit } from '@/api/account';
Expand Down Expand Up @@ -52,6 +52,20 @@ const validateSpacing = (values: string[], elements: Element[]) => {

describe('Amount formatting', () => {

beforeAll(() => {
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: (query: string) => ({
matches: false,
media: query,
onchange: null,
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
}),
});
});

beforeEach(() => {
(useContext as Mock).mockReturnValue({
hideAmounts: false,
Expand Down
4 changes: 4 additions & 0 deletions frontends/web/src/components/balance/balance.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ vi.mock('@/utils/request', () => ({
apiGet: vi.fn().mockResolvedValue({}),
}));

vi.mock('@/hooks/mediaquery', () => ({
useMediaQuery: vi.fn().mockReturnValue(true)
}));

vi.mock('react', () => ({
useMemo: vi.fn().mockImplementation((fn) => fn()),
useContext: vi.fn(),
Expand Down

0 comments on commit 750aae2

Please sign in to comment.