Skip to content

Instantly share code, notes, and snippets.

@cmstead
cmstead / extended-simple-ui-test-runner.js
Last active February 7, 2017 06:48
Extended test runner for UI tests
(function (testRunner) {
'use strict';
function logAndTestUi(sample, expectedMean, expectedStandardDeviation) {
var message = 'Testing -- ' +
'sample: ' + JSON.stringify(sample) + '; ' +
'expected mean: ' + expectedMean + '; ' +
'expected standard deviation: ' + expectedStandardDeviation;
console.log(message);
@cmstead
cmstead / testSnippets.json
Last active May 3, 2017 16:03
My test snippets for VS Code
{
"Mocha describe": {
"prefix": "mdesc",
"body": [
"describe('$1', function () {",
"\t$2",
"});"
],
@cmstead
cmstead / Tests for multiplyThenDivide
Last active October 1, 2017 19:53
Example of testing composite multiplyThenDivide, many cases
describe('multiplyThenDivide', function() {
it('should return 0 when multiplying by 0, dividing by 2', function() {
assert.equal(multiplyThenDivide(0, 1, 2), 0);
});
it('should return half of value when multiplying by 5, dividing by 2', function() {
assert.equal(multiplyThenDivide(1, 5, 2), 2.5);
});
@cmstead
cmstead / quickspec-multiplyThenDivide.js
Last active October 1, 2017 19:56
Example of testing composition of multiply and divide with Quickspec
describe('runMultiplyThenDivide', function() {
it('should properly evaluate the composition of multiply and divide', function () {
const specSet = [
{
name: 'Zero-multiplication',
setupValues: { a: 0, b: 1, c: 2 },
expectedValue: 0
},
{
@cmstead
cmstead / multiply-then-divide-composition.js
Created October 1, 2017 20:46
MultiplyThenDivide composition
const multiply = (a, b) => a * b;
const divide = (a, b) => a / b;
const multiplyThenDivide = (a, b, c) => divide(multiply(a, b), c);
@cmstead
cmstead / memoized-lazy-id.js
Created October 11, 2017 06:45
Lazy ID with memoization
const nullFn = (fn) => typeof fn === 'function' ? fn : () => null;
function dict(key, value, struct) {
return (function (localStruct) {
return (ref) => ref === key ? value : localStruct(ref)
})(nullFn(struct));
}
function memoize(fn) {
let store = null;
@cmstead
cmstead / astHelper.js
Created December 28, 2017 23:00
Ast Helper File from JS Refactor source code
'use strict';
function astHelper(estraverse, typeHelper) {
function noOp() { }
function coordsContainedIn(containerCoords, testCoords) {
const onOrAfterStart = testCoords.start.line > containerCoords.start.line
|| (testCoords.start.line === containerCoords.start.line
&& testCoords.start.column >= containerCoords.start.column);
@cmstead
cmstead / typeHelperExample.js
Created December 28, 2017 23:08
Simplified type helper for JS Refactor example source types
'use strict';
const signet = require('signet')();
(function () {
signet.defineDuckType('astPosition', {
line: 'leftBoundedInt<1>',
column: 'leftBoundedInt<0>'
@cmstead
cmstead / astHelper.test.js
Created December 29, 2017 00:18
AST Helper Test File
'use strict';
const assert = require('chai').assert;
const sinon = require('sinon');
const container = require('../../../container');
const motherContainer = require('../../test-utils/mother-container');
const testUtils = require('../../test-utils/test-utils');
require('../../test-utils/approvalsConfig');
@cmstead
cmstead / windowFakeAndTesting.js
Created February 15, 2018 22:39
Testing when using window
describe('myTest', function () {
it('should interact with window', function () {
function AudioContext() {
this.foo = 'bar';
}
AudioContext.prototype = {
doThatThingYouDo: sinon.spy()
};