11// @flow
22import Vue from 'vue'
3+ import semver from 'semver'
34
45export function throwError ( msg : string ) : void {
56 throw new Error ( `[vue-test-utils]: ${ msg } ` )
@@ -31,10 +32,6 @@ const hyphenateRE = /\B([A-Z])/g
3132export const hyphenate = ( str : string ) : string =>
3233 str . replace ( hyphenateRE , '-$1' ) . toLowerCase ( )
3334
34- export const vueVersion = Number (
35- `${ Vue . version . split ( '.' ) [ 0 ] } .${ Vue . version . split ( '.' ) [ 1 ] } `
36- )
37-
3835function hasOwnProperty ( obj , prop ) {
3936 return Object . prototype . hasOwnProperty . call ( obj , prop )
4037}
@@ -59,16 +56,28 @@ export function resolveComponent (id: string, components: Object) {
5956 return components [ id ] || components [ camelizedId ] || components [ PascalCaseId ]
6057}
6158
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'
7279 }
73- return false
80+
81+ // change is handler for version 2.0 - 2.1.8, and 2.5+
82+ return 'change'
7483}
0 commit comments