Skip to content

Commit 799ef30

Browse files
committed
add test case for incorrect h injection
1 parent 989a279 commit 799ef30

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

test/test.js

+23-6
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ describe('babel-plugin-transform-vue-jsx', () => {
207207
expect(vnode.data.class).to.deep.equal({ a: true, b: true })
208208
})
209209

210-
it('h self-defining in object methods', () => {
210+
it('h injection in object methods', () => {
211211
const obj = {
212212
method () {
213213
return <div>test</div>
@@ -218,7 +218,24 @@ describe('babel-plugin-transform-vue-jsx', () => {
218218
expect(vnode.children[0].text).to.equal('test')
219219
})
220220

221-
it('h self-defining in object getters', () => {
221+
it('h should not be injected in nested JSX expressions', () => {
222+
const obj = {
223+
method () {
224+
return <div foo={{
225+
render () {
226+
return <div>bar</div>
227+
}
228+
}}>test</div>
229+
}
230+
}
231+
const vnode = render(h => obj.method.call({ $createElement: h }))
232+
expect(vnode.tag).to.equal('div')
233+
const nested = vnode.data.attrs.foo.render()
234+
expect(nested.tag).to.equal('div')
235+
expect(nested.children[0].text).to.equal('bar')
236+
})
237+
238+
it('h injection in object getters', () => {
222239
const obj = {
223240
get computed () {
224241
return <div>test</div>
@@ -232,7 +249,7 @@ describe('babel-plugin-transform-vue-jsx', () => {
232249
expect(vnode.children[0].text).to.equal('test')
233250
})
234251

235-
it('h self-defining in multi-level object getters', () => {
252+
it('h injection in multi-level object getters', () => {
236253
const obj = {
237254
inherited: {
238255
get computed () {
@@ -248,7 +265,7 @@ describe('babel-plugin-transform-vue-jsx', () => {
248265
expect(vnode.children[0].text).to.equal('test')
249266
})
250267

251-
it('h self-defining in class methods', () => {
268+
it('h injection in class methods', () => {
252269
class Test {
253270
constructor (h) {
254271
this.$createElement = h
@@ -262,7 +279,7 @@ describe('babel-plugin-transform-vue-jsx', () => {
262279
expect(vnode.children[0].text).to.equal('test')
263280
})
264281

265-
it('h self-defining in class getters', () => {
282+
it('h injection in class getters', () => {
266283
class Test {
267284
constructor (h) {
268285
this.$createElement = h
@@ -276,7 +293,7 @@ describe('babel-plugin-transform-vue-jsx', () => {
276293
expect(vnode.children[0].text).to.equal('test')
277294
})
278295

279-
it('h self-defining in methods with parameters', () => {
296+
it('h injection in methods with parameters', () => {
280297
class Test {
281298
constructor (h) {
282299
this.$createElement = h

0 commit comments

Comments
 (0)