This file contains hidden or 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
describe("updateFooSaga", () => { | |
afterEach(() => { | |
global.fetch = jest.fn().mockReset(); | |
}); | |
const gen = updateFooSaga(updateFoo(mockFoo)); | |
it("should handle successful fetch request", () => { | |
global.fetch = jest.fn().mockResolvedValueOnce({ | |
ok: true, | |
json: () => Promise.resolve(mockSuccessResponse), | |
}); |
This file contains hidden or 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
beforeEach(() => { | |
jest.spyOn(window, 'location', 'get').mockReturnValue({ | |
...window.location, | |
href: 'https://myapp.com' | |
}); | |
}); |
This file contains hidden or 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
"test": "jest --detectOpenHandles --forceExit --coverage --collectCoverageFrom=src/components/common/**/*.{js,jsx,ts,tsx} src/components/common/", |
This file contains hidden or 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
process.env.npm_package_name | |
process.env.npm_package_... |
This file contains hidden or 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
import * as utils from '../utils'; | |
utils.isSomething = jest.fn(() => true); |
This file contains hidden or 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
const utilityObj = require('../../utils/obj'); | |
jest.mock('../../utils/obj', () => { | |
return { | |
...jest.requireActual(''../../utils/obj'), | |
getDefaultOptions: jest.fn((req, path) => { | |
console.log('mock', path) | |
return // mocked stuff | |
}), | |
} |
This file contains hidden or 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
import { SOME_VALUE } from '../constants'; | |
jest.mock('../constants', () => ({ SOME_VALUE: 'abc123test' })); |
This file contains hidden or 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
function enummaker(obj = {}) { | |
let newEnum = obj; | |
newEnum[Symbol.iterator] = function() { | |
let i = 0; | |
let keys = Object.keys(this); | |
return { | |
next: function() { | |
let value = keys[i]; | |
i++; |
This file contains hidden or 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
function singletonMaker(key, klassname, namespace) { | |
if (!window[namespace]) { | |
window[namespace] = {}; | |
} | |
const keySymbol = Symbol.for(key); | |
const globalSymbols = Object.getOwnPropertySymbols(namespace); | |
const hasKey = (globalSymbols.indexOf(keySymbol) > -1); | |
if (!hasKey) { |
This file contains hidden or 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
const mutationObserver = new MutationObserver((e) => { | |
if (e[0].removedNodes) { | |
console.log('%cremoved nodes %o', 'color:aquamarine', e[0].removedNodes); | |
} | |
}); | |
// watch just the child nodes | |
mutationObserver.observe(document.querySelector('main'), { childList: true }); |
NewerOlder