This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +52
-3
lines changed
2 files changed +52
-3
lines changed Original file line number Diff line number Diff line change 12
12
* @description
13
13
* This is very simple implementation of testing browser's features.
14
14
*/
15
- function $SnifferProvider ( ) {
16
- this . $get = [ '$window' , function ( $window ) {
15
+ function $SnifferProvider ( ) {
16
+ this . $get = [ '$window' , function ( $window ) {
17
+ var eventSupport = { } ;
18
+
17
19
return {
18
20
history : ! ! ( $window . history && $window . history . pushState ) ,
19
21
hashchange : 'onhashchange' in $window &&
20
22
// IE8 compatible mode lies
21
- ( ! $window . document . documentMode || $window . document . documentMode > 7 )
23
+ ( ! $window . document . documentMode || $window . document . documentMode > 7 ) ,
24
+ hasEvent : function ( event ) {
25
+ if ( isUndefined ( eventSupport [ event ] ) ) {
26
+ var divElm = $window . document . createElement ( 'div' ) ;
27
+ eventSupport [ event ] = 'on' + event in divElm ;
28
+ }
29
+
30
+ return eventSupport [ event ] ;
31
+ }
22
32
} ;
23
33
} ] ;
24
34
}
Original file line number Diff line number Diff line change @@ -30,4 +30,43 @@ describe('$sniffer', function() {
30
30
expect ( sniffer ( { onhashchange : true , document : { documentMode : 7 } } ) . hashchange ) . toBe ( false ) ;
31
31
} ) ;
32
32
} ) ;
33
+
34
+
35
+ describe ( 'hasEvent' , function ( ) {
36
+ var mockDocument , mockDivElement , $sniffer ;
37
+
38
+ beforeEach ( function ( ) {
39
+ mockDocument = { createElement : jasmine . createSpy ( 'createElement' ) } ;
40
+ mockDocument . createElement . andCallFake ( function ( elm ) {
41
+ if ( elm === 'div' ) return mockDivElement ;
42
+ } ) ;
43
+
44
+ $sniffer = sniffer ( { document : mockDocument } ) ;
45
+ } ) ;
46
+
47
+
48
+ it ( 'should return true if "oninput" is present in a div element' , function ( ) {
49
+ mockDivElement = { oninput : noop } ;
50
+
51
+ expect ( $sniffer . hasEvent ( 'input' ) ) . toBe ( true ) ;
52
+ } ) ;
53
+
54
+
55
+ it ( 'should return false if "oninput" is not present in a div element' , function ( ) {
56
+ mockDivElement = { } ;
57
+
58
+ expect ( $sniffer . hasEvent ( 'input' ) ) . toBe ( false ) ;
59
+ } ) ;
60
+
61
+
62
+ it ( 'should only create the element once' , function ( ) {
63
+ mockDivElement = { } ;
64
+
65
+ $sniffer . hasEvent ( 'input' ) ;
66
+ $sniffer . hasEvent ( 'input' ) ;
67
+ $sniffer . hasEvent ( 'input' ) ;
68
+
69
+ expect ( mockDocument . createElement ) . toHaveBeenCalledOnce ( ) ;
70
+ } ) ;
71
+ } ) ;
33
72
} ) ;
You can’t perform that action at this time.
0 commit comments