This file contains 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 type { ZodTypeAny, z } from 'zod'; | |
//@see https://zod.dev/?id=writing-generic-functions | |
export const createFetch = <Output extends ZodTypeAny>( | |
zodSchema: Output | |
): ((input: RequestInfo | URL, init?: RequestInit) => Promise<z.infer<Output>>) => { | |
return (input, init) => | |
fetch(input, init).then((res) => { | |
if (!res.ok) { | |
throw new Error(res.statusText); |
This file contains 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
tell application "Brave Browser" | |
activate | |
repeat with w in (windows) | |
set j to 0 | |
repeat with t in (tabs of w) | |
set j to j + 1 | |
if title of t contains "YOUR_NAME" then | |
set (active tab index of w) to j | |
set index of w to 1 | |
tell application "System Events" to tell process "Brave Browser" |
This file contains 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
// dump to your desktop the contents of a component at a point in time | |
// htmlDump(component); | |
function htmlDump(component: RenderResult) { | |
const fs = require('fs'); | |
const path = require('path'); | |
const os = require('os'); | |
const rtl = require('react-testing-library'); | |
const dir = os.homedir() + '/Desktop/htmlDump'; | |
if (!fs.existsSync(dir)) { |
This file contains 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
jest.mock('moment', () => { | |
const mock = (timeStamp: string = '2022-09-29T00:00:00Z') => | |
jest.requireActual('moment')(timeStamp); | |
return Object.assign(mock, jest.requireActual('moment')); | |
}); |
This file contains 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
/** | |
* @param {Object} object | |
* @param {'GET'|'POST'|'PUT'|'PATCH'|'DELETE'} verb | |
* @returns {FormData} | |
*/ | |
export function objectToFormData (object, verb = 'POST') { | |
const formData = Object.keys(object).reduce((formData, key) => { | |
const value = typeof object[key] === 'boolean' | |
? Number(object[key]) | |
: object[key] |
This file contains 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
export default (interrogate, mockImplementations = {}) => { | |
const spies = {} | |
interrogate.prototype && Object.getOwnPropertyNames(interrogate.prototype).forEach((name) => { | |
if (name !== 'constructor') { | |
spies[`${name}Spy`] = createSpy(interrogate.prototype, mockImplementations, name) | |
} | |
// AFAIK, you can't spy on a constructor | |
// top answer is here: https://stackoverflow.com/a/48486214/1090606 | |
// For now, mock the entire module to assert that the constructor was called correctly. |
This file contains 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
// run this in the browser console. | |
function buildJSON(streams) { | |
clear(); | |
var mock = [] | |
var mockTrack = (stream) => { | |
const output = stream.reduce((acc, next) => { | |
const clone = {} | |
for (var i in next) { | |
if (typeof next[i] === 'string' || typeof next[i] === 'boolean') { |
This file contains 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
#set($pascalCaseName = ${StringUtils.removeAndHump($NAME, '-')}) | |
#set($titleCaseName = ${pascalCaseName.replaceAll("([A-Z])", " $1").trim()}) | |
import { mountFunction } from 'tests/unit/mount' | |
import $pascalCaseName from '@/components/#if($folder != '')$folder/#end$pascalCaseName' | |
import { getLastEvent, getLastItemFromArray } from 'tests/helpers' | |
describe('$titleCaseName', () => { | |
beforeEach(() => { | |
}) |
This file contains 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
Array.from({length: 5}, (_,index) => ++index) // length of 5, and a callback to fill a value [1,2,3,4,5] |
This file contains 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
export function createProvider (vm) { | |
const provider = {} | |
return (properties) => { | |
properties.forEach((property) => { | |
const [[key, alias = null]] = typeof property === 'string' | |
? [[property]] | |
: Object.entries(property) | |
Object.defineProperty(provider, key, { | |
enumerable: true, | |
get: () => vm[alias || key] |
NewerOlder