Skip to content

Instantly share code, notes, and snippets.

View aphofstede's full-sized avatar

Alexander Hofstede aphofstede

View GitHub Profile
@aphofstede
aphofstede / Cache.Extention.php
Last active April 13, 2018 11:10
Cached function calling
/**
* call_user_func_array_cached
*
* @param function, variable args
* @return object
*/
function call_user_func_array_cached( $function, $param_arr )
{
// ----------------------------------------------------------
@aphofstede
aphofstede / axios-test.spec.js
Created April 9, 2018 15:30
Reproduction of an issue with a test that tests a debounced async Vue component function
// See https://stackoverflow.com/questions/47907000/testing-debounced-asynchronous-request-with-moxios-and-faketimers
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import axios from 'axios'
import moxios from 'moxios'
import _ from 'lodash'
import expect from 'expect'
import sinon from 'sinon'
let Debounced = Vue.component('Debounced',
@aphofstede
aphofstede / mounted-test.spec.js
Created April 13, 2018 11:05
An example test that tests an axios call is made in a Vue component's mounted() function
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import expect from 'expect'
import axios from 'axios'
import moxios from 'moxios'
import sinon from "sinon"
describe ('Test axios in mounted()', () => {
let wrapper
@aphofstede
aphofstede / timer.spec.js
Created April 13, 2018 11:10
debounce with fake timer test
import expect from 'expect'
import sinon from 'sinon'
import _ from 'lodash'
describe.only ('Debounce', () => {
let clock
beforeEach(() => {
clock = sinon.useFakeTimers();
})