-
-
Notifications
You must be signed in to change notification settings - Fork 150
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 #65 from open-source-labs/test-utils
Test utils library
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// overwrite window.require method to prevent errors when executing utils.ts without electron | ||
window.require = ((str: string) => str) as any | ||
|
||
// eslint-disable-next-line import/first | ||
import * as utils from '../../../frontend/lib/utils'; | ||
|
||
describe('once', () => { | ||
it('should only run once', () => { | ||
let counter = 0; | ||
const cb = () => { | ||
counter += 1; | ||
}; | ||
const limitedFunc = utils.once(cb); | ||
|
||
expect(counter).toBe(0) | ||
limitedFunc() | ||
expect(counter).toBe(1) | ||
limitedFunc() | ||
expect(counter).toBe(1) | ||
limitedFunc() | ||
expect(counter).toBe(1) | ||
}); | ||
}); | ||
|
||
describe('readingTime', () => { | ||
it('should never be less than 3s',() => { | ||
expect(utils.readingTime('short')).toBe(3000) | ||
}) | ||
}) |