Skip to content

Commit

Permalink
feat: Return the component from render (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilTholin authored and benmonro committed May 3, 2019
1 parent c386099 commit c2ccb27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ const mountedContainers = new Set()
export const render = (Component, options) => {
const target = document.body.appendChild(document.createElement('div'))

const rendered = new Component({
const component = new Component({
...options,
target,
})

mountedContainers.add(rendered)
mountedContainers.add(component)
return {
component,
...getQueriesForElement(document.body),
}
}
Expand Down
12 changes: 11 additions & 1 deletion tests/queries.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {render, fireEvent, waitForElement, cleanup} from '../src'
import {render, fireEvent, wait, waitForElement, cleanup} from '../src'
import App from './example/App.svelte'
import 'jest-dom/extend-expect'

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

expect(button).toBeInTheDocument()
})

test('programmatically change props', async () => {
const {component, getByText} = render(App, {props: {name: 'world'}})

expect(getByText('Hello world!')).toBeInTheDocument()

component.$set({name: 'foo'})

await wait(() => expect(getByText('Hello foo!')).toBeInTheDocument())
})
})

0 comments on commit c2ccb27

Please sign in to comment.