File tree 6 files changed +14582
-815
lines changed
6 files changed +14582
-815
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"presets" : [
3
- " env"
3
+ [ " @babel/preset- env" ]
4
4
]
5
5
}
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @jest -environment jsdom
3
+ */
4
+
5
+ import { mount } from '@vue/test-utils'
6
+
7
+ import clickOutSide from "../lib" ;
8
+
9
+ import Box from './Component.vue'
10
+
11
+ test ( 'box element is not visible at first' , ( ) => {
12
+ const wrapper = mount ( Box )
13
+
14
+ expect ( wrapper . find ( '.box' ) . exists ( ) ) . toBe ( true )
15
+ } )
16
+
17
+ test ( 'box counter increases if button is clicked' , async ( ) => {
18
+ const wrapper = mount ( Box )
19
+
20
+ expect ( wrapper . find ( '.box' ) . exists ( ) ) . toBe ( true )
21
+
22
+ const button = wrapper . find ( '.box' )
23
+ await button . trigger ( 'click' )
24
+
25
+ expect ( wrapper . find ( '.box' ) . text ( ) ) . toBe ( 'BOX 1' )
26
+ } )
27
+
28
+ // TODO: fix it.
29
+ test ( 'box element is invisible if data visible is false' , async ( ) => {
30
+ const wrapper = mount ( Box , {
31
+ global : {
32
+ directives : {
33
+ clickOutSide,
34
+ }
35
+ }
36
+ } )
37
+
38
+ const box = wrapper . find ( '.box' )
39
+ const main = wrapper . find ( 'main' )
40
+
41
+ expect ( box . exists ( ) ) . toBe ( true )
42
+
43
+ await main . trigger ( 'click' )
44
+
45
+ expect ( box . isVisible ( ) ) . toBe ( false )
46
+ } )
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <main >
3
+ <div
4
+ v-if =" visible"
5
+ @click =" counter++"
6
+ v-click-out-side =" customMethod"
7
+ class =" box"
8
+ >
9
+ BOX {{ counter }}
10
+ </div >
11
+ <br />
12
+ <p >Outside of the box</p >
13
+ </main >
14
+ </template >
15
+
16
+ <script >
17
+ import clickOutSide from " ../lib" ;
18
+
19
+ export default {
20
+ name: " Box" ,
21
+ directives: {
22
+ clickOutSide,
23
+ },
24
+ data () {
25
+ return {
26
+ visible: true ,
27
+ counter: 0 ,
28
+ };
29
+ },
30
+ methods: {
31
+ customMethod () {
32
+ this .visible = false ;
33
+ },
34
+ },
35
+ };
36
+ </script >
37
+
38
+ <style scoped>
39
+ div {
40
+ display : flex ;
41
+ align-items : center ;
42
+ justify-content : center ;
43
+ font-size : 2rem ;
44
+ background-color : red ;
45
+ width : 100px ;
46
+ height : 100px ;
47
+ }
48
+ p {
49
+ font-size : 2rem ;
50
+ font-weight : 800 ;
51
+ }
52
+ </style >
You can’t perform that action at this time.
0 commit comments