11import isCtrlOrMetaKey from "./index"
22
3- // https://github.com/facebook/jest/issues/717#issuecomment-369872760
4-
5- test ( "non-macOS" , ( ) => {
3+ // Mocks a non-macOS user agent.
4+ function mockNonMacOS ( ) {
65 Object . defineProperty ( window . navigator , "userAgent" , {
76 value : "..." ,
87 configurable : true ,
98 } )
9+ }
10+
11+ // Mocks a macOS user agent.
12+ function mockMacOS ( ) {
13+ Object . defineProperty ( window . navigator , "userAgent" , {
14+ value : "... Mac OS X ..." ,
15+ configurable : true ,
16+ } )
17+ }
18+
19+ test ( "non-macOS" , ( ) => {
20+ mockNonMacOS ( )
1021 /* eslint-disable no-multi-spaces */
1122 expect ( isCtrlOrMetaKey ( { metaKey : false , ctrlKey : false } ) ) . not . toBeTruthy ( )
1223 expect ( isCtrlOrMetaKey ( { metaKey : false , ctrlKey : true } ) ) . toBeTruthy ( )
@@ -16,10 +27,7 @@ test("non-macOS", () => {
1627} )
1728
1829test ( "macOS" , ( ) => {
19- Object . defineProperty ( window . navigator , "userAgent" , {
20- value : "... Mac OS X ..." ,
21- configurable : true ,
22- } )
30+ mockMacOS ( )
2331 /* eslint-disable no-multi-spaces */
2432 expect ( isCtrlOrMetaKey ( { metaKey : false , ctrlKey : false } ) ) . not . toBeTruthy ( )
2533 expect ( isCtrlOrMetaKey ( { metaKey : false , ctrlKey : true } ) ) . not . toBeTruthy ( )
0 commit comments