-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from technote-space/release/next-v0.0.36
release: v0.1.0
- Loading branch information
Showing
6 changed files
with
228 additions
and
366 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,8 +1,26 @@ | ||
/* eslint-disable no-magic-numbers */ | ||
import {add} from '../src'; | ||
import {add, repeat} from '../src'; | ||
|
||
describe('add', () => { | ||
it('should add number', () => { | ||
expect(add(1, 2)).toBe(3); | ||
}); | ||
}); | ||
|
||
describe('repeat', () => { | ||
it('should not call callback', async() => { | ||
const callback = jest.fn(); | ||
|
||
await repeat(callback, 0); | ||
|
||
expect(callback).not.toBeCalled(); | ||
}); | ||
|
||
it('should call callback 3 times', async() => { | ||
const callback = jest.fn(); | ||
|
||
await repeat(callback, 3); | ||
|
||
expect(callback).toBeCalledTimes(3); | ||
}); | ||
}); |
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,3 +1,3 @@ | ||
import {setupGlobal} from '@technote-space/github-action-test-helper'; | ||
|
||
setupGlobal(); | ||
jest.mock('./src/constant', () => Object.assign(jest.requireActual('./src/constant'), { | ||
INTERVAL_MS: 0, | ||
})); |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const WAIT_MS = 1000; |
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,12 @@ | ||
import {WAIT_MS} from './constant'; | ||
|
||
export const add = (num1: number, num2: number): number => num1 + num2; | ||
|
||
const wait = (): Promise<void> => new Promise(resolve => setTimeout(resolve, WAIT_MS)); | ||
export const repeat = (callback: () => void, times: number): Promise<void> => { | ||
return [...Array(times).keys()].reduce(async(prev) => { | ||
await prev; | ||
callback(); | ||
await wait(); | ||
}, Promise.resolve()); | ||
}; |
Oops, something went wrong.