Skip to content

Commit

Permalink
test(jsx/dom): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
usualoma committed Aug 18, 2024
1 parent bb5ad26 commit 32c4b02
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/jsx/dom/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,16 @@ describe('DOM', () => {
})
})

describe('dangerouslySetInnerHTML', () => {
it('string', () => {
const App = () => {
return <div dangerouslySetInnerHTML={{ __html: '<p>Hello</p>' }} />
}
render(<App />, root)
expect(root.innerHTML).toBe('<div><p>Hello</p></div>')
})
})

describe('Event', () => {
it('bubbling phase', async () => {
const clicked: string[] = []
Expand Down Expand Up @@ -884,6 +894,13 @@ describe('DOM', () => {
render(<App />, root)
expect(addEventListenerSpy).not.toHaveBeenCalled()
})

it('invalid event handler value', async () => {
const App = () => {
return <div onClick={1 as unknown as () => void}></div>
}
expect(() => render(<App />, root)).toThrow()
})
})

it('simple Counter', async () => {
Expand Down Expand Up @@ -1874,6 +1891,16 @@ describe('DOM', () => {
await Promise.resolve()
expect(root.innerHTML).toBe('<div><p>1</p></div>')
})

it('title', async () => {
const App = () => {
return <div>{createElement('title', {}, 'Hello')}</div>
}
const app = <App />
render(app, root)
expect(document.head.innerHTML).toBe('<title>Hello</title>')
expect(root.innerHTML).toBe('<div></div>')
})
})

describe('dom-specific createElement', () => {
Expand All @@ -1889,6 +1916,16 @@ describe('DOM', () => {
await Promise.resolve()
expect(root.innerHTML).toBe('<div><p>1</p></div>')
})

it('title', async () => {
const App = () => {
return <div>{createElementForDom('title', {}, 'Hello')}</div>
}
const app = <App />
render(app, root)
expect(document.head.innerHTML).toBe('<title>Hello</title>')
expect(root.innerHTML).toBe('<div></div>')
})
})

describe('cloneElement', () => {
Expand Down

0 comments on commit 32c4b02

Please sign in to comment.