| 1 |
/** |
| 2 |
* @license |
| 3 |
* Copyright 2022 Google LLC |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
*/ |
| 6 |
|
| 7 |
import {assert} from 'chai'; |
| 8 |
|
| 9 |
import React from 'react'; |
| 10 |
// eslint-disable-next-line import/extensions |
| 11 |
import {render, unmountComponentAtNode} from 'react-dom'; |
| 12 |
import {ElementProps} from '@lit-internal/test-element-a-react/element-props.js'; |
| 13 |
import {ElementProps as ElementPropsElement} from '@lit-internal/test-element-a/element-props.js'; |
| 14 |
|
| 15 |
suite('test-element-props', () => { |
| 16 |
let container: HTMLElement; |
| 17 |
|
| 18 |
setup(() => { |
| 19 |
container = document.createElement('div'); |
| 20 |
document.body.appendChild(container); |
| 21 |
}); |
| 22 |
|
| 23 |
teardown(() => { |
| 24 |
if (container && container.parentNode) { |
| 25 |
unmountComponentAtNode(container); |
| 26 |
container.parentNode.removeChild(container); |
| 27 |
} |
| 28 |
}); |
| 29 |
|
| 30 |
test('renders correctly', async () => { |
| 31 |
const props = { |
| 32 |
aStr: 'Hi', |
| 33 |
aBool: true, |
| 34 |
aMyType: { |
| 35 |
a: 'a', |
| 36 |
b: 2, |
| 37 |
c: false, |
| 38 |
d: ['1'], |
| 39 |
e: 'unknown', |
| 40 |
strOrNum: 5, |
| 41 |
}, |
| 42 |
}; |
| 43 |
render( |
| 44 |
<React.StrictMode> |
| 45 |
<ElementProps {...props}></ElementProps> |
| 46 |
</React.StrictMode>, |
| 47 |
container |
| 48 |
); |
| 49 |
const el = container.querySelector('element-props')! as ElementPropsElement; |
| 50 |
await el.updateComplete; |
| 51 |
const shadowRoot = el.shadowRoot!; |
| 52 |
Object.entries(props).forEach(([k, v]) => { |
| 53 |
const e = shadowRoot.getElementById(k as string)!; |
| 54 |
assert.equal(el[k as keyof ElementPropsElement], v); |
| 55 |
assert.equal( |
| 56 |
e.textContent, |
| 57 |
typeof v === 'object' ? JSON.stringify(v) : String(v) |
| 58 |
); |
| 59 |
}); |
| 60 |
}); |
| 61 |
}); |