File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed
test/specs/mounting-options Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -71,8 +71,21 @@ export default function createInstance(
71
71
// used to identify extended component using constructor
72
72
componentOptions . $_vueTestUtils_original = component
73
73
74
- // make sure all extends are based on this instance
74
+ // watchers provided in mounting options should override preexisting ones
75
+ if ( componentOptions . watch && instanceOptions . watch ) {
76
+ const componentWatchers = Object . keys ( componentOptions . watch )
77
+ const instanceWatchers = Object . keys ( instanceOptions . watch )
78
+
79
+ for ( let i = 0 ; i < instanceWatchers . length ; i ++ ) {
80
+ const k = instanceWatchers [ i ]
81
+ // override the componentOptions with the one provided in mounting options
82
+ if ( componentWatchers . includes ( k ) ) {
83
+ componentOptions . watch [ k ] = instanceOptions . watch [ k ]
84
+ }
85
+ }
86
+ }
75
87
88
+ // make sure all extends are based on this instance
76
89
const Constructor = _Vue . extend ( componentOptions ) . extend ( instanceOptions )
77
90
componentOptions . _Ctor = { }
78
91
Constructor . options . _base = _Vue
Original file line number Diff line number Diff line change
1
+ import { describeWithShallowAndMount } from '~resources/utils'
2
+
3
+ describeWithShallowAndMount ( 'options.watch' , mountingMethod => {
4
+ it ( 'overrides a default watch handler' , async ( ) => {
5
+ const TestComponent = {
6
+ props : [ 'someProp' ] ,
7
+ template : '<div>{{ foo }}</div>' ,
8
+ data ( ) {
9
+ return {
10
+ foo : 'bar'
11
+ }
12
+ } ,
13
+ watch : {
14
+ someProp : {
15
+ handler ( ) {
16
+ this . foo = 'updated-bar'
17
+ }
18
+ }
19
+ }
20
+ }
21
+ const wrapper = mountingMethod ( TestComponent , {
22
+ watch : {
23
+ someProp : {
24
+ handler ( ) {
25
+ // do nothing
26
+ }
27
+ }
28
+ }
29
+ } )
30
+
31
+ wrapper . setProps ( { someProp : 'some-new-val' } )
32
+ await wrapper . vm . $nextTick ( )
33
+
34
+ expect ( wrapper . text ( ) ) . to . equal ( 'bar' )
35
+ } )
36
+ } )
You can’t perform that action at this time.
0 commit comments