|
| 1 | +import renderer from 'react-test-renderer'; |
| 2 | +import JsonView from './'; |
| 3 | + |
| 4 | +const avatar = 'https://i.imgur.com/MK3eW3As.jpg'; |
| 5 | +const longArray = new Array(1000).fill(1); |
| 6 | +const example = { |
| 7 | + avatar, |
| 8 | + string: 'Lorem ipsum dolor sit amet', |
| 9 | + integer: 42, |
| 10 | + float: 114.514, |
| 11 | + // @ts-ignore |
| 12 | + bigint: 10086n, |
| 13 | + null: null, |
| 14 | + undefined, |
| 15 | + timer: 0, |
| 16 | + date: new Date('Tue Sep 13 2022 14:07:44 GMT-0500 (Central Daylight Time)'), |
| 17 | + array: [19, 100.86, 'test', NaN, Infinity], |
| 18 | + nestedArray: [ |
| 19 | + [1, 2], |
| 20 | + [3, 4], |
| 21 | + ], |
| 22 | + object: { |
| 23 | + 'first-child': true, |
| 24 | + 'second-child': false, |
| 25 | + 'last-child': null, |
| 26 | + }, |
| 27 | + longArray, |
| 28 | + string_number: '1234', |
| 29 | +}; |
| 30 | + |
| 31 | +it('renders <JsonView /> test case', () => { |
| 32 | + const component = renderer.create(<JsonView value={example} />); |
| 33 | + let tree = component.toJSON(); |
| 34 | + expect(tree).toHaveProperty('type'); |
| 35 | + expect(tree).toHaveProperty('props'); |
| 36 | + expect(tree).toHaveProperty('children'); |
| 37 | + expect(tree).toHaveProperty('type', 'div'); |
| 38 | + expect(tree).toHaveProperty('props.className', 'w-json-view-container w-rjv w-rjv-inner'); |
| 39 | + expect(tree).toHaveProperty('props.style.backgroundColor', 'var(--w-rjv-background-color, #00000000)'); |
| 40 | + expect(tree).toHaveProperty('props.style', { |
| 41 | + lineHeight: 1.4, |
| 42 | + fontSize: 13, |
| 43 | + fontFamily: 'var(--w-rjv-font-family, Menlo, monospace)', |
| 44 | + color: 'var(--w-rjv-color, #002b36)', |
| 45 | + backgroundColor: 'var(--w-rjv-background-color, #00000000)', |
| 46 | + }); |
| 47 | + expect(tree).toHaveProperty('props.onMouseEnter'); |
| 48 | + expect(tree).toHaveProperty('props.onMouseLeave'); |
| 49 | +}); |
0 commit comments