Skip to content

Instantly share code, notes, and snippets.

View idir's full-sized avatar

Idir IBOUCHICHENE idir

View GitHub Profile
@renaudtertrais
renaudtertrais / mock-global-object-jest.js
Created May 17, 2017 12:00
A simple way to mock/unmock globals object methods or constant
/* global expect jest */
const delay = ms => fn => setTimeout(fn, ms);
const mockGlobalProperty = globalObject => key => value => {
// save original implementation in order to unmock later
const original = globalObject[key];
// mock key on the global object
Object.defineProperty(globalObject, key, { value, writable: true });