-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,700 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@coldwired/react": patch | ||
--- | ||
|
||
fix some bugs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { useState } from 'react'; | ||
|
||
import { createRoot, defaultSchema, type Manifest } from '.'; | ||
|
||
const NAME_ATTRIBUTE = defaultSchema.nameAttribute; | ||
const REACT_COMPONENT_TAG = 'react-component'; | ||
const DEFAULT_TAG_NAME = 'react-fragment'; | ||
|
||
const Counter = () => { | ||
const [count, setCount] = useState(0); | ||
return ( | ||
<div> | ||
<p>Count: {count}</p> | ||
<button onClick={() => setCount((count) => count + 1)}>Increment</button> | ||
</div> | ||
); | ||
}; | ||
const manifest: Manifest = { Counter }; | ||
|
||
describe('@coldwired/react', () => { | ||
describe('root with custom schema', () => { | ||
it('render simple fragment', async () => { | ||
document.body.innerHTML = `<${DEFAULT_TAG_NAME}><div class="title">Hello</div></${DEFAULT_TAG_NAME}><div id="root"></div>`; | ||
const root = createRoot(document.getElementById('root')!, { | ||
loader: (name) => Promise.resolve(manifest[name]), | ||
schema: { | ||
fragmentTagName: DEFAULT_TAG_NAME, | ||
componentTagName: REACT_COMPONENT_TAG, | ||
}, | ||
}); | ||
await root.mount(); | ||
await root.render(document.body).done; | ||
|
||
expect(document.body.innerHTML).toEqual( | ||
`<${DEFAULT_TAG_NAME}><div class="title">Hello</div></${DEFAULT_TAG_NAME}><div id="root"></div>`, | ||
); | ||
|
||
await root.render(document.body.firstElementChild!, `<div class="title">Hello World!</div>`) | ||
.done; | ||
expect(document.body.innerHTML).toEqual( | ||
`<${DEFAULT_TAG_NAME}><div class="title">Hello World!</div></${DEFAULT_TAG_NAME}><div id="root"></div>`, | ||
); | ||
expect(root.getCache().size).toEqual(1); | ||
root.destroy(); | ||
}); | ||
|
||
it('render fragment with component', async () => { | ||
document.body.innerHTML = `<${DEFAULT_TAG_NAME}><${REACT_COMPONENT_TAG} ${NAME_ATTRIBUTE}="Counter"></${REACT_COMPONENT_TAG}></${DEFAULT_TAG_NAME}><div id="root"></div>`; | ||
const root = createRoot(document.getElementById('root')!, { | ||
loader: (name) => Promise.resolve(manifest[name]), | ||
schema: { | ||
fragmentTagName: DEFAULT_TAG_NAME, | ||
componentTagName: REACT_COMPONENT_TAG, | ||
}, | ||
}); | ||
await root.mount(); | ||
await root.render(document.body).done; | ||
|
||
expect(document.body.innerHTML).toEqual( | ||
`<${DEFAULT_TAG_NAME}><div><p>Count: 0</p><button>Increment</button></div></${DEFAULT_TAG_NAME}><div id="root"></div>`, | ||
); | ||
root.destroy(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.