Skip to content

Instantly share code, notes, and snippets.

View sharmaadityaHQ's full-sized avatar
🎯
Focusing

Aditya Sharma sharmaadityaHQ

🎯
Focusing
View GitHub Profile
@sharmaadityaHQ
sharmaadityaHQ / machine.js
Last active June 15, 2021 09:01
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@sharmaadityaHQ
sharmaadityaHQ / MockFnFactory.js
Created April 27, 2020 14:32
Mock functions or spies in Jest
// The mock function factory
function fn(impl = () => {}) {
const mockFn = function(...args) {
mockFn.mock.calls.push(args)
mockFn.mock.instances.push(this)
try {
const value = impl.apply(this, args)
mockFn.mock.results.push({ type: "return", value })
return value
}