Skip to content

Instantly share code, notes, and snippets.

View vmasto's full-sized avatar

Vassilis Mastorostergios vmasto

  • Thessaloniki, Greece
View GitHub Profile
@vmasto
vmasto / mock.js
Created February 8, 2017 00:06
Simple JavaScript mocking function
const mock = impl => {
const mockFn = (...args) => {
mockFn.calls.push(args);
return impl ? impl(...args) : undefined;
};
mockFn.calls = [];
mockFn.reset = () => mockFn.calls = [];
return mockFn;
@BinaryMuse
BinaryMuse / restful.js
Last active March 17, 2019 08:22
Express API with Async/Await
import express from "express";
/**
* Takes a route handling function and returns a function
* that wraps it after first checking that the strings in
* `reserved` are not part of `req.body`. Used for ensuring
* create and update requests do not overwrite server-generated
* values.
*/
function checkReservedParams(routeHandler, ...reserved) {