Skip to content

Commit

Permalink
feat: spread all of options on component (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmonro authored May 3, 2019
1 parent 2b95e85 commit c386099
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

## Installation

`npm i -D svelte-testing-library`
`npm i -D svlt-testing-library`

## Usage

App.svelte

```html
<script>
export let name;
export let name
</script>

<style>
Expand All @@ -27,13 +27,23 @@ App.svelte
App.spec.js

```javascript
import App from "../src/App.svelte";
import { render } from "../src";
describe("App", () => {
test("should render", () => {
const { getByText } = render(App, { name: "world" });

expect(getByText("Hello world!"));
});
});
import App from '../src/App.svelte'
import {render} from '../src'
describe('App', () => {
test('should render greeting', () => {
const {getByText} = render(App, {props: {name: 'world'}})

expect(getByText('Hello world!'))
})

test('should change button text after click', async () => {
const {getByText} = render(App, {props: {name: 'world'}})

fireEvent.click(getByText('Button Text'))

const button = await waitForElement(() => getByText('Button Clicked'))

expect(button).toBeInTheDocument()
})
})
```
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import {getQueriesForElement} from 'dom-testing-library'

export * from 'dom-testing-library'
const mountedContainers = new Set()
export const render = (Component, props) => {
const container = document.body.appendChild(document.createElement('div'))
export const render = (Component, options) => {
const target = document.body.appendChild(document.createElement('div'))

const rendered = new Component({
target: container,
props,
...options,
target,
})

mountedContainers.add(rendered)
Expand Down
4 changes: 2 additions & 2 deletions tests/queries.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import 'jest-dom/extend-expect'
afterEach(cleanup)
describe('queries', () => {
test('getByText', () => {
const {getByText} = render(App, {name: 'world'})
const {getByText} = render(App, {props: {name: 'world'}})

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

test('click button', async () => {
const {getByText} = render(App, {name: 'world'})
const {getByText} = render(App, {props: {name: 'world'}})

fireEvent.click(getByText('Button Text'))

Expand Down

0 comments on commit c386099

Please sign in to comment.