1
1
import { compileToFunctions } from 'vue-template-compiler'
2
2
import ComponentWithMethods from '~resources/components/component-with-methods.vue'
3
+ import ComponentWithEvents from '~resources/components/component-with-events.vue'
3
4
import { describeWithShallowAndMount } from '~resources/utils'
4
5
5
6
describeWithShallowAndMount ( 'setMethods' , ( mountingMethod ) => {
@@ -10,18 +11,23 @@ describeWithShallowAndMount('setMethods', (mountingMethod) => {
10
11
expect ( wrapper . vm . someMethod ) . to . equal ( someMethod )
11
12
} )
12
13
13
- it ( 'sets component data and updates nested vm nodes when called on Vue instance' , ( ) => {
14
- const wrapper = mountingMethod ( ComponentWithMethods )
15
- const someMethod = ( ) => console . log ( 'hey' )
16
- wrapper . setMethods ( { someMethod } )
17
- expect ( wrapper . vm . someMethod ) . to . equal ( someMethod )
18
- } )
19
-
20
14
it ( 'throws an error if node is not a Vue instance' , ( ) => {
21
15
const message = 'wrapper.setMethods() can only be called on a Vue instance'
22
16
const compiled = compileToFunctions ( '<div><p></p></div>' )
23
17
const wrapper = mountingMethod ( compiled )
24
18
const p = wrapper . find ( 'p' )
25
19
expect ( ( ) => p . setMethods ( { ready : true } ) ) . throw ( Error , message )
26
20
} )
21
+
22
+ it ( 'should replace methods when tied to an event' , ( ) => {
23
+ const wrapper = mountingMethod ( ComponentWithEvents )
24
+ expect ( wrapper . vm . isActive ) . to . be . false
25
+ wrapper . find ( '.toggle' ) . trigger ( 'click' )
26
+ expect ( wrapper . vm . isActive ) . to . be . true
27
+ // Replace the toggle function so that the data supposedly won't change
28
+ const toggleActive = ( ) => console . log ( 'overriden' )
29
+ wrapper . setMethods ( { toggleActive } )
30
+ wrapper . find ( '.toggle' ) . trigger ( 'click' )
31
+ expect ( wrapper . vm . isActive ) . to . be . true
32
+ } )
27
33
} )
0 commit comments