Skip to content
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

feat: spread all of options on component #2

Merged
merged 1 commit into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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