-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathproductUtils.test.tsx
More file actions
37 lines (31 loc) · 1.15 KB
/
Copy pathproductUtils.test.tsx
File metadata and controls
37 lines (31 loc) · 1.15 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
import { render } from '@testing-library/react';
import {
createAccessibleProductLabel,
createStrikeThroughProductLabel,
} from './productUtils';
describe('createStrikeThroughProductLabel', () => {
it('returns the label unchanged when there is no struck-through text', () => {
const { container } = render(
<>{createStrikeThroughProductLabel('£5 at Shop')}</>,
);
expect(container.textContent).toBe('£5 at Shop');
expect(container.querySelector('s')).toBeNull();
});
it('renders the old price in an s element and preserves the rest', () => {
const { container } = render(
<>{createStrikeThroughProductLabel('~£10~ £5 at Shop')}</>,
);
expect(container.querySelector('s')).toHaveTextContent('£10');
expect(container.textContent).toBe('£10 £5 at Shop');
});
});
describe('createAccessibleProductLabel', () => {
it('returns the label unchanged when there is no struck-through text', () => {
expect(createAccessibleProductLabel('£5 at Shop')).toBe('£5 at Shop');
});
it('describes the old and new prices accessibly', () => {
expect(createAccessibleProductLabel('~£10~ £5 at Shop')).toBe(
'Was £10, now £5 at Shop',
);
});
});