Skip to content

Check the default property of Component for the constructor #34

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

Merged
merged 1 commit into from
Jun 10, 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
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const config = Object.assign(jestConfig, {
transform: {
...jestConfig.transform,
'^.+\\.svelte$': 'jest-transform-svelte',
'^.+\\.html$': 'svelte-test/transform',
},
transformIgnorePatterns: [
...jestConfig.transformIgnorePatterns,
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"rollup-plugin-svelte": "^5.0.3",
"rollup-plugin-terser": "^4.0.4",
"sirv-cli": "^0.4.0",
"svelte": "^3.0.0"
"svelte": "^3.0.0",
"svelte-test": "^0.3.0"
},
"peerDependencies": {
"svelte": "3.x"
Expand Down Expand Up @@ -58,4 +59,4 @@
"dist",
"public"
]
}
}
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const render = (Component, {target, ...options} = {}) => {
target = document.body.appendChild(document.createElement('div'))
}

const component = new Component({
const ComponentConstructor = Component.default || Component
const component = new ComponentConstructor({
...options,
target,
})
Expand Down
19 changes: 19 additions & 0 deletions tests/example/App.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
export let name;

let buttonText = "Button Text";

function handleClick() {
buttonText = "Button Clicked";
}
</script>

<style>
h1 {
color: purple;
}
</style>

<h1>Hello {name}!</h1>

<button on:click={handleClick}>{buttonText}</button>
7 changes: 7 additions & 0 deletions tests/render.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
prettyDOM,
} from '../src'
import App from './example/App.svelte'
import App2 from './example/App.html'
import 'jest-dom/extend-expect'

afterEach(cleanup)
Expand Down Expand Up @@ -82,4 +83,10 @@ describe('render', () => {

cleanup()
})

test('correctly find component constructor on the default property', () => {
const {getByText} = render(App2, {props: {name: 'world'}})

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