@@ -23,6 +23,7 @@ describe("Heart", () => {
23
23
} )
24
24
afterEach ( ( ) => {
25
25
jest . resetAllMocks ( )
26
+ jest . useRealTimers ( )
26
27
if ( heart ) {
27
28
heart . dispose ( )
28
29
}
@@ -42,11 +43,7 @@ describe("Heart", () => {
42
43
expect ( fileContents ) . toBe ( text )
43
44
44
45
heart = new Heart ( pathToFile , mockIsActive ( true ) )
45
- heart . beat ( )
46
- // HACK@jsjoeio - beat has some async logic but is not an async method
47
- // Therefore, we have to create an artificial wait in order to make sure
48
- // all async code has completed before asserting
49
- await new Promise ( ( r ) => setTimeout ( r , 100 ) )
46
+ await heart . beat ( )
50
47
// Check that the heart wrote to the heartbeatFilePath and overwrote our text
51
48
const fileContentsAfterBeat = await readFile ( pathToFile , { encoding : "utf8" } )
52
49
expect ( fileContentsAfterBeat ) . not . toBe ( text )
@@ -56,15 +53,11 @@ describe("Heart", () => {
56
53
} )
57
54
it ( "should log a warning when given an invalid file path" , async ( ) => {
58
55
heart = new Heart ( `fakeDir/fake.txt` , mockIsActive ( false ) )
59
- heart . beat ( )
60
- // HACK@jsjoeio - beat has some async logic but is not an async method
61
- // Therefore, we have to create an artificial wait in order to make sure
62
- // all async code has completed before asserting
63
- await new Promise ( ( r ) => setTimeout ( r , 100 ) )
56
+ await heart . beat ( )
64
57
expect ( logger . warn ) . toHaveBeenCalled ( )
65
58
} )
66
- it ( "should be active after calling beat" , ( ) => {
67
- heart . beat ( )
59
+ it ( "should be active after calling beat" , async ( ) => {
60
+ await heart . beat ( )
68
61
69
62
const isAlive = heart . alive ( )
70
63
expect ( isAlive ) . toBe ( true )
0 commit comments