@@ -2,11 +2,11 @@ import {
2
2
expect ,
3
3
describe ,
4
4
beforeAll ,
5
- jest ,
5
+ vi ,
6
6
afterAll ,
7
7
afterEach ,
8
8
it ,
9
- } from "bun:test " ;
9
+ } from "vitest " ;
10
10
11
11
import { hotkey } from "./hotkey.ts" ;
12
12
@@ -30,14 +30,14 @@ describe("hotkey", function () {
30
30
} ) ;
31
31
32
32
it ( "calls callback when callback provided" , function ( ) {
33
- const callback = jest . fn ( ) ;
33
+ const callback = vi . fn ( ) ;
34
34
action = hotkey ( element , { code : spaceKeyCode , callback } ) ;
35
35
dispatchKeydownEvent ( { code : spaceKeyCode } ) ;
36
36
expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
37
37
} ) ;
38
38
39
39
it ( "clicks node when callback not provided" , function ( ) {
40
- const callback = jest . fn ( ) ;
40
+ const callback = vi . fn ( ) ;
41
41
action = hotkey ( element , { code : spaceKeyCode } ) ;
42
42
element . addEventListener ( "click" , callback ) ;
43
43
dispatchKeydownEvent ( { code : spaceKeyCode } ) ;
@@ -46,36 +46,36 @@ describe("hotkey", function () {
46
46
} ) ;
47
47
48
48
it ( "does not call callback when different key pressed" , function ( ) {
49
- const callback = jest . fn ( ) ;
49
+ const callback = vi . fn ( ) ;
50
50
action = hotkey ( element , { code : spaceKeyCode , callback } ) ;
51
51
dispatchKeydownEvent ( { code : "KeyA" } ) ;
52
52
expect ( callback ) . not . toHaveBeenCalled ( ) ;
53
53
} ) ;
54
54
55
55
it ( "handles alt key" , function ( ) {
56
- const callback = jest . fn ( ) ;
56
+ const callback = vi . fn ( ) ;
57
57
action = hotkey ( element , { code : spaceKeyCode , callback, alt : true } ) ;
58
58
dispatchKeydownEvent ( { code : spaceKeyCode , altKey : true } ) ;
59
59
expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
60
60
} ) ;
61
61
62
62
it ( "handles shift key" , function ( ) {
63
- const callback = jest . fn ( ) ;
63
+ const callback = vi . fn ( ) ;
64
64
action = hotkey ( element , { code : spaceKeyCode , callback, shift : true } ) ;
65
65
dispatchKeydownEvent ( { code : spaceKeyCode , shiftKey : true } ) ;
66
66
expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
67
67
} ) ;
68
68
69
69
it ( "handles ctrl and meta key" , function ( ) {
70
- const callback = jest . fn ( ) ;
70
+ const callback = vi . fn ( ) ;
71
71
action = hotkey ( element , { code : spaceKeyCode , callback, control : true } ) ;
72
72
dispatchKeydownEvent ( { code : spaceKeyCode , ctrlKey : true } ) ;
73
73
dispatchKeydownEvent ( { code : spaceKeyCode , metaKey : true } ) ;
74
74
expect ( callback ) . toHaveBeenCalledTimes ( 2 ) ;
75
75
} ) ;
76
76
77
77
it ( "updates key code" , function ( ) {
78
- const callback = jest . fn ( ) ;
78
+ const callback = vi . fn ( ) ;
79
79
action = hotkey ( element , { code : spaceKeyCode , callback } ) ;
80
80
action ?. update ?.( { code : "KeyA" , callback } ) ;
81
81
dispatchKeydownEvent ( { code : "KeyA" } ) ;
@@ -84,7 +84,7 @@ describe("hotkey", function () {
84
84
} ) ;
85
85
86
86
it ( "does not fire callback when it is inactive" , function ( ) {
87
- const callback = jest . fn ( ) ;
87
+ const callback = vi . fn ( ) ;
88
88
action = hotkey ( element , { code : spaceKeyCode , callback } ) ;
89
89
dispatchKeydownEvent ( { code : spaceKeyCode } ) ;
90
90
action ?. update ?.( { active : false , code : spaceKeyCode , callback } ) ;
0 commit comments