-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkeleton.test.tsx
More file actions
46 lines (39 loc) · 1.53 KB
/
Skeleton.test.tsx
File metadata and controls
46 lines (39 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React from 'react';
import { Animated } from 'react-native';
import { gray, Skeleton } from '../src';
import { render } from './test-utils';
describe('Skeleton component', () => {
let colorSchemeSpy: jest.SpyInstance;
beforeEach(() => {
jest.useFakeTimers();
jest.clearAllMocks();
colorSchemeSpy = jest.spyOn(require('react-native'), 'useColorScheme');
});
afterEach(() => {
jest.clearAllMocks();
colorSchemeSpy.mockRestore();
});
it('renders with default background in light mode', () => {
colorSchemeSpy.mockReturnValue('light');
const { getByTestId } = render(<Skeleton testID="skeleton" />);
const skeleton = getByTestId('skeleton');
expect(skeleton.props.style.backgroundColor).toBe(gray[400]);
});
it('renders with default background in dark mode', () => {
colorSchemeSpy.mockReturnValue('dark');
const { getByTestId } = render(<Skeleton testID="skeleton" />);
const skeleton = getByTestId('skeleton');
expect(skeleton.props.style.backgroundColor).toBe(gray[800]);
});
it('uses the custom backgroundColor when provided', () => {
colorSchemeSpy.mockReturnValue('light');
const { getByTestId } = render(<Skeleton testID="skeleton" backgroundColor="red" />);
const skeleton = getByTestId('skeleton');
expect(skeleton.props.style.backgroundColor).toBe('red');
});
it('starts shimmer animation on mount', () => {
const loopSpy = jest.spyOn(Animated, 'loop');
render(<Skeleton testID="skeleton" />);
expect(loopSpy).toHaveBeenCalled();
});
});