File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -407,6 +407,17 @@ export default class Wrapper implements BaseWrapper {
407
407
return _props || { } // Return an empty object if no props exist
408
408
}
409
409
410
+ /**
411
+ * Sets vm data object while preserving existing k/v
412
+ */
413
+ setDataObj ( obj : string , key : string , value : any ) {
414
+ if ( obj === undefined ) {
415
+ this . vm . $set ( this . vm , key , value )
416
+ } else {
417
+ this . vm . $set ( obj , key , value )
418
+ }
419
+ }
420
+
410
421
/**
411
422
* Sets vm data
412
423
*/
Original file line number Diff line number Diff line change
1
+ import {
2
+ describeWithShallowAndMount ,
3
+ vueVersion
4
+ } from '~resources/utils'
5
+
6
+ describeWithShallowAndMount ( 'setDataObj' , ( mountingMethod ) => {
7
+ let info
8
+
9
+ beforeEach ( ( ) => {
10
+ info = sinon . stub ( console , 'info' )
11
+ } )
12
+
13
+ afterEach ( ( ) => {
14
+ info . restore ( )
15
+ } )
16
+ it ( 'should allow for setting a data value' , ( ) => {
17
+ const TestComponent = {
18
+ data : ( ) => ( {
19
+ text : 'hello'
20
+ } )
21
+ }
22
+ const wrapper = mountingMethod ( TestComponent )
23
+ wrapper . setDataObj ( wrapper . vm , 'text' , 'goodbye' )
24
+ expect ( wrapper . vm . text ) . to . equal ( 'goodbye' )
25
+ } )
26
+ it ( 'should allow for setting a data object' , ( ) => {
27
+ const TestComponent = {
28
+ data : ( ) => ( {
29
+ message : {
30
+ text : 'hello'
31
+ }
32
+ } )
33
+ }
34
+ const wrapper = mountingMethod ( TestComponent )
35
+ wrapper . setDataObj ( wrapper . vm . message , 'read' , true )
36
+ expect ( wrapper . vm . message . text ) . to . equal ( 'hello' )
37
+ expect ( wrapper . vm . message . read ) . to . equal ( true )
38
+ } )
39
+ } )
You can’t perform that action at this time.
0 commit comments