Skip to content

Instantly share code, notes, and snippets.

@ctbui
ctbui / gist:d59346cbe555e6bec25961d4b5f8bb55
Last active January 25, 2021 16:04
some tests on async await and promises all
const timeoutPromise = timeout =>
new Promise(resolve => setTimeout(resolve, timeout));
describe('some tests on async await and promises all', function() {
it('should run async function in map loop', async function(done) {
// GIVEN
const mockFunction = jest.fn();
const asyncFunctionWithAwait = async timeout => {
await timeoutPromise(timeout);
@ctbui
ctbui / axios-vs-superagent-vs-got.js
Last active December 23, 2020 16:23 — forked from natesilva/axios-vs-superagent.js
Compare performance of Axios vs. SuperAgent when running under Node.js
const Benchmark = require('benchmark');
const axios = require('axios');
const got = require('got');
const superagent = require('superagent');
const suite = new Benchmark.Suite();
const targetUrl = 'http://httpbin.org/ip';
suite
// https://medium.freecodecamp.org/here-are-examples-of-everything-new-in-ecmascript-2016-2017-and-2018-d52fa3b5a70e
// EcmaScript2017
// 1. Object.values()
const car = {BMW: 1, Audi: 2, Tesla: 3};
console.log(Object.values(car)); // [1, 2, 3]
// ESMA2015
console.log(Object.keys(car)); // ["BMW", "Audi", "Tesla"]
// https://medium.freecodecamp.org/here-are-examples-of-everything-new-in-ecmascript-2016-2017-and-2018-d52fa3b5a70e
// 1. Array.prototype.includes
const trois = {id:3};
const arr = [1, "deux", trois, NaN];
console.log(arr.includes(1)); // true
console.log(arr.includes("deux")); // true
console.log(arr.includes(trois)); // true
console.log(arr.includes(NaN)); // true
console.log(arr.includes(4)); // false