Skip to content

Commit 60c5c69

Browse files
authored
Merge pull request #62 from mihar-22/issue-59
feat: allow easier passing in of props
2 parents e315af9 + a2ebeaf commit 60c5c69

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,11 @@
7676
"eslint-plugin-svelte3": "^2.7.3",
7777
"husky": "^3.0.8",
7878
"jest": "^24.7.1",
79-
"jest-transform-svelte": "^2.1.0",
8079
"lint-staged": "^9.4.1",
8180
"npm-run-all": "^4.1.5",
8281
"prettier": "^1.18.2",
8382
"svelte": "^3.0.0",
84-
"svelte-test": "^0.4.0"
83+
"svelte-jester": "^1.0.3"
8584
},
8685
"husky": {
8786
"hooks": {
@@ -122,8 +121,8 @@
122121
],
123122
"transform": {
124123
"^.+\\.js$": "babel-jest",
125-
"^.+\\.svelte$": "jest-transform-svelte",
126-
"^.+\\.html$": "svelte-test/transform"
124+
"^.+\\.svelte$": "svelte-jester",
125+
"^.+\\.html$": "svelte-jester"
127126
},
128127
"moduleFileExtensions": [
129128
"js",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`render should accept svelte component options 1`] = `
4+
<body>
5+
<div>
6+
<h1
7+
data-testid="test"
8+
>
9+
Hello
10+
World
11+
!
12+
</h1>
13+
14+
<button>
15+
Button
16+
</button>
17+
<div />
18+
</div>
19+
</body>
20+
`;

src/__tests__/render.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ describe('render', () => {
4040
expect(getByText('Hello Worlds!')).toBeInTheDocument()
4141
})
4242

43+
test('should accept props directly', () => {
44+
const { getByText } = stlRender(Comp, { name: 'World' })
45+
expect(getByText('Hello World!')).toBeInTheDocument()
46+
})
47+
48+
test('should accept svelte component options', () => {
49+
const target = document.createElement('div')
50+
const div = document.createElement('div')
51+
document.body.appendChild(target)
52+
target.appendChild(div)
53+
const { container } = stlRender(Comp, {
54+
target,
55+
anchor: div,
56+
props: { name: 'World' }
57+
})
58+
expect(container).toMatchSnapshot()
59+
})
60+
4361
test('should return a container object, which contains the DOM of the rendered component', () => {
4462
const { container } = render()
4563

src/pure.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { tick } from 'svelte'
44
const containerCache = new Map()
55
const componentCache = new Set()
66

7+
const svleteComponentOptions = ['anchor', 'props', 'hydrate', 'intro']
8+
79
const render = (
810
Component,
911
{ target, ...options } = {},
@@ -13,10 +15,11 @@ const render = (
1315
target = target || container.appendChild(document.createElement('div'))
1416

1517
const ComponentConstructor = Component.default || Component
18+
const isProps = !Object.keys(options).some(option => svleteComponentOptions.includes(option))
1619

1720
const component = new ComponentConstructor({
1821
target,
19-
...options
22+
...(isProps ? { props: options } : options)
2023
})
2124

2225
containerCache.set(container, { target, component })

0 commit comments

Comments
 (0)