@gooddata/js-utils
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -7,4 +7,4 @@ "use strict"; | ||
exports.postpone = postpone; | ||
function postpone(fn) { | ||
var timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
function postpone(fn, done) { | ||
var timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1; | ||
@@ -14,6 +14,7 @@ setTimeout(function () { | ||
fn(); | ||
done(); | ||
} catch (error) { | ||
console.error(error); // eslint-disable-line no-console | ||
done(error); | ||
} | ||
}, timeout); | ||
} |
{ | ||
"name": "@gooddata/js-utils", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Various utils shared on GoodData frontend", | ||
"main": "lib/index.js", | ||
"typings": "index.d.ts", | ||
"files": [ | ||
"README.md", | ||
"LICENSE", | ||
"lib", | ||
"src" | ||
"src", | ||
"index.d.ts" | ||
], | ||
@@ -21,3 +24,3 @@ "repository": { | ||
"scripts": { | ||
"build": "rm -rf lib && babel src --out-dir lib --ignore .test.js", | ||
"build": "rm -rf lib && babel src --out-dir lib --ignore .test.js", | ||
"prepublish": "yarn run build", | ||
@@ -43,3 +46,3 @@ "test": "jest --watch" | ||
}, | ||
"license": "UNLICENSED", | ||
"license": "BSD-3-Clause", | ||
"jest": { | ||
@@ -46,0 +49,0 @@ "transform": { |
@@ -1,9 +0,10 @@ | ||
export function postpone(fn, timeout = 1) { | ||
export function postpone(fn, done, timeout = 1) { | ||
setTimeout(() => { | ||
try { | ||
fn(); | ||
done(); | ||
} catch (error) { | ||
console.error(error); // eslint-disable-line no-console | ||
done(error); | ||
} | ||
}, timeout); | ||
} |
@@ -6,22 +6,23 @@ import { postpone } from '../test'; | ||
describe('postpone', () => { | ||
it('should call function after timeout', () => { | ||
it('should call fn and doneFn after timeout', () => { | ||
const fn = jest.fn(); | ||
postpone(fn, 1); | ||
const doneFn = jest.fn(); | ||
postpone(fn, doneFn, 1); | ||
jest.runAllTimers(); | ||
expect(fn).toHaveBeenCalled(); | ||
expect(doneFn).toHaveBeenCalled(); | ||
}); | ||
it('should report error if something failed', () => { | ||
const originalConsole = global.console; | ||
const mockedConsoleError = jest.fn(); | ||
global.console = { error: mockedConsoleError }; | ||
it('should call doneFn with error', () => { | ||
const fn = () => { throw Error('failed'); }; | ||
const doneFn = jest.fn(); | ||
const fn = () => { throw Error('failed'); }; | ||
postpone(fn, 1); | ||
postpone(fn, doneFn, 1); | ||
jest.runAllTimers(); | ||
expect(mockedConsoleError).toHaveBeenCalled(); | ||
global.console = originalConsole; | ||
expect(doneFn).toBeCalledWith(Error('failed')); | ||
}); | ||
}); | ||
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
34370
24
0
795