Skip to content

Customize the container #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
EmilTholin opened this issue May 3, 2019 · 1 comment
Closed

Customize the container #9

EmilTholin opened this issue May 3, 2019 · 1 comment

Comments

@EmilTholin
Copy link
Contributor

EmilTholin commented May 3, 2019

Since a Svelte component is compiled, it's a little bit harder to be flexible with what elements should wrap the component than what it is in e.g. React where you can wrap your component with some custom JSX directly inline in the test.

With this in mind, what do you think about taking some inspiration from react-testing-library and allowing the user to customize the target themselves?

- export const render = (Component, options) => {
+ export const render = (Component, { target, ...options }) => {
+   if (!target) {
+     target = document.body.appendChild(document.createElement('div'))
+   }

   // ...
 }
test('it renders properly in a table', async () => {
  const table = document.createElement('table')
  document.body.appendChild(table)

  const utils = render(MyTableBody, {target: table})

  // ...
})
@EmilTholin EmilTholin changed the title Customize the container and base element Customize the container May 3, 2019
@benmonro
Copy link
Member

benmonro commented May 3, 2019

You read my mind. My plan was to add that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants