forked from jamaljsr/polar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme.spec.ts
29 lines (26 loc) · 952 Bytes
/
theme.spec.ts
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
import React from 'react';
import { render } from '@testing-library/react';
import { changeTheme, DOM_ID } from './theme';
describe('Theme Util', () => {
const createStyle = () => {
const style = document.createElement('link');
style.type = 'text/css';
style.rel = 'stylesheet';
style.id = DOM_ID;
style.href = '/themes/dark.css';
return style;
};
it('should change stylesheet', () => {
const { container } = render(React.createElement('div'));
container.append(createStyle());
changeTheme('light');
const style = container.querySelector('link') as HTMLLinkElement;
expect(style.href).toMatch(/.*\/themes\/light.css/);
});
it('should not change theme if link tag is missing', () => {
const { container } = render(React.createElement('div'));
changeTheme('light');
const style = container.querySelector('link') as HTMLLinkElement;
expect(style).not.toBeInTheDocument();
});
});