1
1
// @flow
2
2
import Vue from 'vue'
3
+ import semver from 'semver'
3
4
4
5
export function throwError ( msg : string ) : void {
5
6
throw new Error ( `[vue-test-utils]: ${ msg } ` )
@@ -31,10 +32,6 @@ const hyphenateRE = /\B([A-Z])/g
31
32
export const hyphenate = ( str : string ) : string =>
32
33
str . replace ( hyphenateRE , '-$1' ) . toLowerCase ( )
33
34
34
- export const vueVersion = Number (
35
- `${ Vue . version . split ( '.' ) [ 0 ] } .${ Vue . version . split ( '.' ) [ 1 ] } `
36
- )
37
-
38
35
function hasOwnProperty ( obj , prop ) {
39
36
return Object . prototype . hasOwnProperty . call ( obj , prop )
40
37
}
@@ -59,16 +56,28 @@ export function resolveComponent (id: string, components: Object) {
59
56
return components [ id ] || components [ camelizedId ] || components [ PascalCaseId ]
60
57
}
61
58
62
- export function semVerGreaterThan ( a : string , b : string ) {
63
- const pa = a . split ( '.' )
64
- const pb = b . split ( '.' )
65
- for ( let i = 0 ; i < 3 ; i ++ ) {
66
- var na = Number ( pa [ i ] )
67
- var nb = Number ( pb [ i ] )
68
- if ( na > nb ) return true
69
- if ( nb > na ) return false
70
- if ( ! isNaN ( na ) && isNaN ( nb ) ) return true
71
- if ( isNaN ( na ) && ! isNaN ( nb ) ) return false
59
+ const UA = typeof window !== 'undefined' &&
60
+ 'navigator' in window &&
61
+ navigator . userAgent . toLowerCase ( )
62
+
63
+ export const isPhantomJS = UA && UA . includes &&
64
+ UA . match ( / p h a n t o m j s / i)
65
+
66
+ export const isEdge = UA && UA . indexOf ( 'edge/' ) > 0
67
+ export const isChrome = UA && / c h r o m e \/ \d + / . test ( UA ) && ! isEdge
68
+
69
+ // get the event used to trigger v-model handler that updates bound data
70
+ export function getCheckedEvent ( ) {
71
+ const version = Vue . version
72
+
73
+ if ( semver . satisfies ( version , '2.1.9 - 2.1.10' ) ) {
74
+ return 'click'
75
+ }
76
+
77
+ if ( semver . satisfies ( version , '2.2 - 2.4' ) ) {
78
+ return isChrome ? 'click' : 'change'
72
79
}
73
- return false
80
+
81
+ // change is handler for version 2.0 - 2.1.8, and 2.5+
82
+ return 'change'
74
83
}
0 commit comments