|
| 1 | +import * as fc from 'fast-check'; |
1 | 2 | import { |
2 | 3 | getCleanPropName, |
3 | 4 | getAbodeElements, |
@@ -62,10 +63,35 @@ describe('helper functions', () => { |
62 | 63 | const abodeElement = document.createElement('div'); |
63 | 64 | abodeElement.setAttribute('data-component', 'TestComponent'); |
64 | 65 | abodeElement.setAttribute('data-prop-test-prop', 'testPropValue'); |
| 66 | + abodeElement.setAttribute('data-prop-number-prop', '12345'); |
| 67 | + abodeElement.setAttribute('data-prop-null-prop', 'null'); |
| 68 | + abodeElement.setAttribute('data-prop-true-prop', 'true'); |
| 69 | + abodeElement.setAttribute('data-prop-empty-prop', ''); |
| 70 | + abodeElement.setAttribute( |
| 71 | + 'data-prop-json-prop', |
| 72 | + '{"id": 12345, "product": "keyboard", "variant": {"color": "blue"}}' |
| 73 | + ); |
65 | 74 |
|
66 | 75 | const props = getElementProps(abodeElement); |
67 | 76 |
|
68 | | - expect(props).toEqual({ testProp: 'testPropValue' }); |
| 77 | + expect(props).toEqual({ |
| 78 | + testProp: 'testPropValue', |
| 79 | + numberProp: 12345, |
| 80 | + nullProp: null, |
| 81 | + trueProp: true, |
| 82 | + emptyProp: '', |
| 83 | + jsonProp: { id: 12345, product: 'keyboard', variant: { color: 'blue' } }, |
| 84 | + }); |
| 85 | + }); |
| 86 | + it('getElementProps parses JSON', () => { |
| 87 | + fc.assert( |
| 88 | + fc.property(fc.jsonObject({ maxDepth: 10 }), data => { |
| 89 | + const abodeElement = document.createElement('div'); |
| 90 | + abodeElement.setAttribute('data-prop-test-prop', JSON.stringify(data)); |
| 91 | + const props = getElementProps(abodeElement); |
| 92 | + expect(props.testProp).toEqual(data); |
| 93 | + }) |
| 94 | + ); |
69 | 95 | }); |
70 | 96 |
|
71 | 97 | it('setAttributes', () => { |
|
0 commit comments