Skip to content

Instantly share code, notes, and snippets.

View oosby's full-sized avatar

Olivia Osby oosby

  • San Jose, CA by way of NC
View GitHub Profile
beforeEach(() => {
jest.spyOn(window, 'location', 'get').mockReturnValue({
...window.location,
href: 'https://myapp.com'
});
});
"test": "jest --detectOpenHandles --forceExit --coverage --collectCoverageFrom=src/components/common/**/*.{js,jsx,ts,tsx} src/components/common/",
process.env.npm_package_name
process.env.npm_package_...
import * as utils from '../utils';
utils.isSomething = jest.fn(() => true);
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
}),
}
import { SOME_VALUE } from '../constants';
jest.mock('../constants', () => ({ SOME_VALUE: 'abc123test' }));
@oosby
oosby / enum
Last active February 17, 2017 20:29
javascript enum
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++;
@oosby
oosby / singletonmaker.js
Created October 17, 2016 20:47
Singleton Maker
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) {
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 });
<snippet>
<content><![CDATA[
gulp.task('${1}', function(){
gulp.${2:src}(${3})
.pipe(${4});
});
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>gt</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->