|
1 | 1 | import '@testing-library/jest-dom' |
2 | 2 | import {render} from '@testing-library/react' |
3 | 3 | import React from 'react' |
4 | | -import Octicon, {AlertIcon} from '../index' |
5 | | - |
6 | | -describe('Octicon component', () => { |
7 | | - let mock |
8 | | - |
9 | | - beforeEach(() => { |
10 | | - mock = jest.spyOn(console, 'warn').mockImplementation(() => jest.fn()) |
11 | | - }) |
12 | | - |
13 | | - afterEach(() => { |
14 | | - expect(mock).toHaveBeenCalledWith( |
15 | | - expect.stringContaining( |
16 | | - `<Octicon> is deprecated. Use icon components on their own instead (e.g. <Octicon icon={AlertIcon} /> → <AlertIcon />)` |
17 | | - ) |
18 | | - ) |
19 | | - mock.mockRestore() |
20 | | - }) |
21 | | - |
22 | | - it('throws an error without a single child or icon prop', () => { |
23 | | - const spy = jest.spyOn(console, 'error').mockImplementation(() => jest.fn()) |
24 | | - expect(() => render(<Octicon />)).toThrow() |
25 | | - expect(() => render(<Octicon icon={null} />)).toThrow() |
26 | | - expect(spy).toHaveBeenCalledWith( |
27 | | - expect.objectContaining({ |
28 | | - message: expect.stringContaining('React.Children.only expected to receive a single React element child') |
29 | | - }) |
30 | | - ) |
31 | | - |
32 | | - spy.mockRestore() |
33 | | - }) |
34 | | - |
35 | | - it('passes props to icon prop', () => { |
36 | | - const {container} = render( |
37 | | - <Octicon aria-label="icon" className="foo" size={20} verticalAlign="middle" icon={AlertIcon} /> |
38 | | - ) |
39 | | - expect(container.querySelector('svg')).toHaveAttribute('aria-label', 'icon') |
40 | | - expect(container.querySelector('svg')).toHaveAttribute('class', 'foo') |
41 | | - expect(container.querySelector('svg')).toHaveAttribute('width', '20') |
42 | | - expect(container.querySelector('svg')).toHaveAttribute('height', '20') |
43 | | - expect(container.querySelector('svg')).toHaveStyle({verticalAlign: 'middle'}) |
44 | | - }) |
45 | | - |
46 | | - it('passes props to icon as child', () => { |
47 | | - const {container} = render( |
48 | | - <Octicon aria-label="icon" className="foo" size={20} verticalAlign="middle"> |
49 | | - <AlertIcon /> |
50 | | - </Octicon> |
51 | | - ) |
52 | | - expect(container.querySelector('svg')).toHaveAttribute('aria-label', 'icon') |
53 | | - expect(container.querySelector('svg')).toHaveAttribute('class', 'foo') |
54 | | - expect(container.querySelector('svg')).toHaveAttribute('width', '20') |
55 | | - expect(container.querySelector('svg')).toHaveAttribute('height', '20') |
56 | | - expect(container.querySelector('svg')).toHaveStyle({verticalAlign: 'middle'}) |
57 | | - }) |
58 | | -}) |
| 4 | +import {AlertIcon} from '../index' |
59 | 5 |
|
60 | 6 | describe('An icon component', () => { |
61 | 7 | it('matches snapshot', () => { |
|
0 commit comments