Skip to content

Commit

Permalink
Merge pull request #65 from open-source-labs/test-utils
Browse files Browse the repository at this point in the history
Test utils library
  • Loading branch information
Claudiohbsantos authored Mar 21, 2021
2 parents f7bca8c + b3891d5 commit caa5685
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions __tests__/frontend/lib/utils.spec.ts
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)
})
})

0 comments on commit caa5685

Please sign in to comment.