|
1 | 1 | import Vue from 'vue' |
2 | 2 |
|
3 | 3 | describe('Component scoped slot', () => { |
| 4 | + it('default slot', () => { |
| 5 | + const vm = new Vue({ |
| 6 | + template: `<test><span slot scope="props">{{ props.msg }}</span></test>`, |
| 7 | + components: { |
| 8 | + test: { |
| 9 | + data () { |
| 10 | + return { msg: 'hello' } |
| 11 | + }, |
| 12 | + template: ` |
| 13 | + <div> |
| 14 | + <slot :msg="msg"></slot> |
| 15 | + </div> |
| 16 | + ` |
| 17 | + } |
| 18 | + } |
| 19 | + }).$mount() |
| 20 | + expect(vm.$el.innerHTML).toBe('<span>hello</span>') |
| 21 | + }) |
| 22 | + |
4 | 23 | it('normal element slot', done => { |
5 | 24 | const vm = new Vue({ |
6 | 25 | template: ` |
@@ -204,25 +223,6 @@ describe('Component scoped slot', () => { |
204 | 223 | expect(vm.$el.innerHTML).toBe('<span>meh</span>') |
205 | 224 | }) |
206 | 225 |
|
207 | | - it('warn un-named scoped slot', () => { |
208 | | - new Vue({ |
209 | | - template: `<test><span scope="lol"></span></test>`, |
210 | | - components: { |
211 | | - test: { |
212 | | - data () { |
213 | | - return { msg: 'hello' } |
214 | | - }, |
215 | | - template: ` |
216 | | - <div> |
217 | | - <slot :msg="msg"></slot> |
218 | | - </div> |
219 | | - ` |
220 | | - } |
221 | | - } |
222 | | - }).$mount() |
223 | | - expect('Scoped slots must be named').toHaveBeenWarned() |
224 | | - }) |
225 | | - |
226 | 226 | it('warn key on slot', () => { |
227 | 227 | new Vue({ |
228 | 228 | template: ` |
@@ -250,7 +250,7 @@ describe('Component scoped slot', () => { |
250 | 250 | expect(`\`key\` does not work on <slot>`).toHaveBeenWarned() |
251 | 251 | }) |
252 | 252 |
|
253 | | - it('render function usage', done => { |
| 253 | + it('render function usage (named, via data)', done => { |
254 | 254 | const vm = new Vue({ |
255 | 255 | render (h) { |
256 | 256 | return h('test', { |
@@ -282,4 +282,50 @@ describe('Component scoped slot', () => { |
282 | 282 | expect(vm.$el.innerHTML).toBe('<span>world</span>') |
283 | 283 | }).then(done) |
284 | 284 | }) |
| 285 | + |
| 286 | + it('render function usage (default, as children)', () => { |
| 287 | + const vm = new Vue({ |
| 288 | + render (h) { |
| 289 | + return h('test', [ |
| 290 | + props => h('span', [props.msg]) |
| 291 | + ]) |
| 292 | + }, |
| 293 | + components: { |
| 294 | + test: { |
| 295 | + data () { |
| 296 | + return { msg: 'hello' } |
| 297 | + }, |
| 298 | + render (h) { |
| 299 | + return h('div', [ |
| 300 | + this.$scopedSlots.default({ msg: this.msg }) |
| 301 | + ]) |
| 302 | + } |
| 303 | + } |
| 304 | + } |
| 305 | + }).$mount() |
| 306 | + expect(vm.$el.innerHTML).toBe('<span>hello</span>') |
| 307 | + }) |
| 308 | + |
| 309 | + it('render function usage (JSX)', () => { |
| 310 | + const vm = new Vue({ |
| 311 | + render (h) { |
| 312 | + return <test>{ |
| 313 | + props => <span>{props.msg}</span> |
| 314 | + }</test> |
| 315 | + }, |
| 316 | + components: { |
| 317 | + test: { |
| 318 | + data () { |
| 319 | + return { msg: 'hello' } |
| 320 | + }, |
| 321 | + render (h) { |
| 322 | + return <div> |
| 323 | + {this.$scopedSlots.default({ msg: this.msg })} |
| 324 | + </div> |
| 325 | + } |
| 326 | + } |
| 327 | + } |
| 328 | + }).$mount() |
| 329 | + expect(vm.$el.innerHTML).toBe('<span>hello</span>') |
| 330 | + }) |
285 | 331 | }) |
0 commit comments