-
-
Notifications
You must be signed in to change notification settings - Fork 549
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
2,095 additions
and
3,605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
/**/*.js | ||
build/** | ||
tmp/** | ||
coverage/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
{ | ||
"parser": "typescript", | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.mts"], | ||
"options": { | ||
"parser": "typescript" | ||
} | ||
} | ||
] | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { describe, it, afterEach, beforeEach, vi, expect } from 'vitest'; | ||
import { Delays, greeter } from '../../src/main.js'; | ||
|
||
describe('greeter function', () => { | ||
const name = 'John'; | ||
|
||
beforeEach(() => { | ||
// Read more about fake timers | ||
// https://vitest.dev/api/vi.html#vi-usefaketimers | ||
vi.useFakeTimers(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.useRealTimers(); | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
// Assert if setTimeout was called properly | ||
it('delays the greeting by 2 seconds', async () => { | ||
vi.spyOn(global, 'setTimeout'); | ||
const p = greeter(name); | ||
|
||
await vi.runAllTimersAsync(); | ||
await p; | ||
|
||
expect(setTimeout).toHaveBeenCalledTimes(1); | ||
expect(setTimeout).toHaveBeenLastCalledWith( | ||
expect.any(Function), | ||
Delays.Long, | ||
); | ||
}); | ||
|
||
// Assert greeter result | ||
it('greets a user with `Hello, {name}` message', async () => { | ||
const p = greeter(name); | ||
await vi.runAllTimersAsync(); | ||
|
||
expect(await p).toBe(`Hello, ${name}`); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.