11const Vue = require ( 'vue/dist/vue.common.js' ) ;
2- const { ref, computed, createElement : h , provide, inject } = require ( '../src' ) ;
2+ const { ref, computed, createElement : h , provide, inject, toRefs } = require ( '../src' ) ;
33
44describe ( 'setup' , ( ) => {
55 beforeEach ( ( ) => {
@@ -51,7 +51,7 @@ describe('setup', () => {
5151 expect ( vm . b ) . toBe ( 1 ) ;
5252 } ) ;
5353
54- it ( 'should work with `methods` and `data` options' , done => {
54+ it ( 'should work with `methods` and `data` options' , ( done ) => {
5555 let calls = 0 ;
5656 const vm = new Vue ( {
5757 template : `<div>{{a}}{{b}}{{c}}</div>` ,
@@ -215,7 +215,7 @@ describe('setup', () => {
215215 expect ( vm . $refs . test . b ) . toBe ( 1 ) ;
216216 } ) ;
217217
218- it ( 'props should not be reactive' , done => {
218+ it ( 'props should not be reactive' , ( done ) => {
219219 let calls = 0 ;
220220 const vm = new Vue ( {
221221 template : `<child :msg="msg"></child>` ,
@@ -247,6 +247,43 @@ describe('setup', () => {
247247 } ) . then ( done ) ;
248248 } ) ;
249249
250+ it ( 'toRefs(props) should not warn' , async ( ) => {
251+ let a ;
252+
253+ const child = {
254+ template : `<div/>` ,
255+
256+ props : {
257+ r : Number ,
258+ } ,
259+ setup ( props ) {
260+ a = toRefs ( props ) . r ;
261+ } ,
262+ } ;
263+
264+ const vm = new Vue ( {
265+ template : `<child :r="r"/>` ,
266+ components : {
267+ child,
268+ } ,
269+
270+ data ( ) {
271+ return {
272+ r : 1 ,
273+ } ;
274+ } ,
275+ } ) . $mount ( ) ;
276+
277+ expect ( a . value ) . toBe ( 1 ) ;
278+ vm . r = 3 ;
279+
280+ await Vue . nextTick ( ) ;
281+
282+ expect ( a . value ) . toBe ( 3 ) ;
283+
284+ expect ( warn ) . not . toHaveBeenCalled ( ) ;
285+ } ) ;
286+
250287 it ( 'this should be undefined' , ( ) => {
251288 const vm = new Vue ( {
252289 template : '<div></div>' ,
@@ -256,7 +293,7 @@ describe('setup', () => {
256293 } ) . $mount ( ) ;
257294 } ) ;
258295
259- it ( 'should not make returned non-reactive object reactive' , done => {
296+ it ( 'should not make returned non-reactive object reactive' , ( done ) => {
260297 const vm = new Vue ( {
261298 setup ( ) {
262299 return {
@@ -285,8 +322,8 @@ describe('setup', () => {
285322 } ) ;
286323
287324 it ( "should put a unenumerable '__ob__' for non-reactive object" , ( ) => {
288- const clone = obj => JSON . parse ( JSON . stringify ( obj ) ) ;
289- const componentSetup = jest . fn ( props => {
325+ const clone = ( obj ) => JSON . parse ( JSON . stringify ( obj ) ) ;
326+ const componentSetup = jest . fn ( ( props ) => {
290327 const internalOptions = clone ( props . options ) ;
291328 return { internalOptions } ;
292329 } ) ;
@@ -329,7 +366,7 @@ describe('setup', () => {
329366 name : 'child' ,
330367 props : [ 'msg' ] ,
331368 setup ( ) {
332- return props => {
369+ return ( props ) => {
333370 p = props ;
334371 return null ;
335372 } ;
@@ -340,7 +377,7 @@ describe('setup', () => {
340377 expect ( p ) . toBe ( undefined ) ;
341378 } ) ;
342379
343- it ( 'inline render function should work' , done => {
380+ it ( 'inline render function should work' , ( done ) => {
344381 // let createElement;
345382 const vm = new Vue ( {
346383 props : [ 'msg' ] ,
@@ -383,44 +420,44 @@ describe('setup', () => {
383420 } ) ;
384421
385422 describe ( 'Methods' , ( ) => {
386- it ( 'binds methods when calling with parenthesis' , async ( ) => {
423+ it ( 'binds methods when calling with parenthesis' , async ( ) => {
387424 let context = null ;
388- const contextFunction = jest . fn ( function ( ) {
389- context = this
425+ const contextFunction = jest . fn ( function ( ) {
426+ context = this ;
390427 } ) ;
391428
392429 const vm = new Vue ( {
393430 template : '<div><button @click="contextFunction()"/></div>' ,
394431 setup ( ) {
395432 return {
396- contextFunction
397- }
398- }
433+ contextFunction,
434+ } ;
435+ } ,
399436 } ) . $mount ( ) ;
400-
437+
401438 await vm . $el . querySelector ( 'button' ) . click ( ) ;
402439 expect ( contextFunction ) . toBeCalled ( ) ;
403440 expect ( context ) . toBe ( vm ) ;
404441 } ) ;
405442
406443 it ( 'binds methods when calling without parenthesis' , async ( ) => {
407444 let context = null ;
408- const contextFunction = jest . fn ( function ( ) {
409- context = this
445+ const contextFunction = jest . fn ( function ( ) {
446+ context = this ;
410447 } ) ;
411448
412449 const vm = new Vue ( {
413450 template : '<div><button @click="contextFunction"/></div>' ,
414451 setup ( ) {
415452 return {
416- contextFunction
417- }
418- }
453+ contextFunction,
454+ } ;
455+ } ,
419456 } ) . $mount ( ) ;
420-
457+
421458 await vm . $el . querySelector ( 'button' ) . click ( ) ;
422459 expect ( contextFunction ) . toBeCalled ( ) ;
423460 expect ( context ) . toBe ( vm ) ;
424461 } ) ;
425- } )
462+ } ) ;
426463} ) ;
0 commit comments