Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c2ccb27

Browse files
EmilTholinbenmonro
authored andcommitted
feat: Return the component from render (#4)
1 parent c386099 commit c2ccb27

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

‎src/index.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ const mountedContainers = new Set()
55
export const render = (Component, options) => {
66
const target = document.body.appendChild(document.createElement('div'))
77

8-
const rendered = new Component({
8+
const component = new Component({
99
...options,
1010
target,
1111
})
1212

13-
mountedContainers.add(rendered)
13+
mountedContainers.add(component)
1414
return {
15+
component,
1516
...getQueriesForElement(document.body),
1617
}
1718
}

‎tests/queries.spec.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {render, fireEvent, waitForElement, cleanup} from '../src'
1+
import {render, fireEvent, wait,waitForElement, cleanup} from '../src'
22
import App from './example/App.svelte'
33
import 'jest-dom/extend-expect'
44

@@ -19,4 +19,14 @@ describe('queries', () => {
1919

2020
expect(button).toBeInTheDocument()
2121
})
22+
23+
test('programmatically change props', async () => {
24+
const {component, getByText} = render(App, {props: {name: 'world'}})
25+
26+
expect(getByText('Hello world!')).toBeInTheDocument()
27+
28+
component.$set({name: 'foo'})
29+
30+
await wait(() => expect(getByText('Hello foo!')).toBeInTheDocument())
31+
})
2232
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /