File tree 4 files changed +58
-6
lines changed
4 files changed +58
-6
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " v-track" ,
3
- "version" : " 0.8.5 " ,
3
+ "version" : " 0.8.6 " ,
4
4
"description" : " 一个基于Vue指令的埋点插件" ,
5
5
"author" : " LHammer <lhammer@qq.com>" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change 2
2
* @Author : 宋慧武
3
3
* @Date : 2019-03-06 17:49:29
4
4
* @Last Modified by: 宋慧武
5
- * @Last Modified time: 2019-05-28 17:05:58
5
+ * @Last Modified time: 2019-08-05 17:43:57
6
6
*/
7
7
import {
8
8
zipArray ,
@@ -107,14 +107,15 @@ export function bind(
107
107
}
108
108
// 区域曝光埋点
109
109
else if ( partialMatch ( "show" ) ) {
110
- const fn = ( ) => events [ id ] ( context ) ;
110
+ const [ args ] = zipArray ( value ) ;
111
+ const tck = events [ id ] . bind ( null , context , ...args ) ;
111
112
const once = partialMatch ( "once" ) ;
112
113
const custom = partialMatch ( "custom" ) ;
113
114
114
115
if ( ! el . $visMonitor ) {
115
116
const vm = new VisMonitor ( el , custom && context . $refs [ value . ref ] ) ;
116
117
117
- ( once ? vm . $once : vm . $on ) . call ( vm , "fullyvisible" , fn ) ;
118
+ ( once ? vm . $once : vm . $on ) . call ( vm , "fullyvisible" , tck ) ;
118
119
el . $visMonitor = vm ;
119
120
}
120
121
} else if (
Original file line number Diff line number Diff line change 2
2
* @Author : 宋慧武
3
3
* @Date : 2019-04-08 11:13:34
4
4
* @Last Modified by: 宋慧武
5
- * @Last Modified time: 2019-04-20 18:06:43
5
+ * @Last Modified time: 2019-08-05 15:31:00
6
6
*/
7
7
8
8
/**
@@ -33,7 +33,7 @@ export const isDef = v => v !== undefined && v !== null;
33
33
* @param {Object } value
34
34
* @returns {Array } [keys, values]
35
35
*/
36
- export function zipArray ( value ) {
36
+ export function zipArray ( value = { } ) {
37
37
return [ Object . values ( value ) , Object . keys ( value ) ] ;
38
38
}
39
39
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Created Date: 2019-08-05
3
+ * Author: 宋慧武
4
+ * ------
5
+ * Last Modified: Monday 2019-08-05 17:01:32 pm
6
+ * Modified By: the developer formerly known as 宋慧武 at <songhuiwu001@ke.com>
7
+ * ------
8
+ * HISTORY:
9
+ * ------
10
+ * Javascript will save your soul!
11
+ */
12
+ import Vue from "vue" ;
13
+ import VTrack from "@/" ;
14
+ import { mount , createLocalVue } from "@vue/test-utils" ;
15
+ import { mockParentNode , mockRect } from "../helper" ;
16
+
17
+ const localVue = createLocalVue ( ) ;
18
+ const mockTrackAction = jest . fn ( ( _ , id ) => id ) ;
19
+ const trackEvents = {
20
+ 18015 : mockTrackAction
21
+ } ;
22
+ const TrackShow = Vue . extend ( {
23
+ template : `
24
+ <div v-track:18015.show="{ id }" />
25
+ ` ,
26
+ data ( ) {
27
+ return {
28
+ id : "2019"
29
+ } ;
30
+ }
31
+ } ) ;
32
+
33
+ localVue . use ( VTrack , {
34
+ trackEvents
35
+ } ) ;
36
+
37
+ jest . useFakeTimers ( ) ;
38
+
39
+ describe ( "TrackShow" , ( ) => {
40
+ it ( "确保DOM元素完全可见之后触发埋点,且至少间隔200ms执行一下" , ( ) => {
41
+ const wrapper = mount ( TrackShow , { localVue } ) ;
42
+ const vm = wrapper . vm ;
43
+
44
+ mockParentNode ( vm . $el ) ;
45
+ mockRect ( vm . $el ) ;
46
+ jest . runAllTimers ( ) ;
47
+
48
+ expect ( mockTrackAction . mock . results [ 0 ] . value ) . toBe ( "2019" ) ;
49
+ expect ( mockTrackAction ) . toBeCalledTimes ( 1 ) ;
50
+ } ) ;
51
+ } ) ;
You can’t perform that action at this time.
0 commit comments