Skip to content

Instantly share code, notes, and snippets.

it('"moveRight()" should increment the "x" propety by 1', function () {
var blocky = new Block(15, 30);
blocky.moveRight();
assert.equal(blocky.x, 16);
});
//....vs....
it('"moveRight()" should increment the "x" propety by 1', function () {
var startingX = 15;
@jhartikainen
jhartikainen / paramTest.js
Created June 12, 2016 12:46
Parametrized test with Mocha example
describe('Something', function() {
var values = ['a', 'b', 'c'];
values.forEach(function(val) {
it('should do something with ' + val + ' in this test', function() {
assert.equal(foo(), val);
});
})
});
@jhartikainen
jhartikainen / tests.js
Created May 13, 2016 10:59
Example of stubbing a complex object
describe('something', function() {
var oldXrm;
beforeEach(function() {
oldXrm = Xrm;
Xrm = {
Page: {
getAttribute: sinon.stub()
}
};
@jhartikainen
jhartikainen / sandbox.js
Last active March 24, 2016 14:05
Manual Sinon sandboxes
describe('something', function() {
var sandbox;
beforeEach(function() {
sandbox = sinon.sandbox.create();
});
afterEach(function() {
sandbox.restore();
});
@jhartikainen
jhartikainen / vuetest.js
Last active February 13, 2016 18:07
Vue.js example component unit test
var assert = require('assert');
var Vue = require('vue');
var TestComponent = Vue.extend({
data: function() {
return {
active: false
};
},
require 'spec_helper'
feature 'foo', :js => true do
it "hi" do
visit "/login"
# this screenshot exposes the issue in this case
save_screenshot('foo.jpg')
end
end
var oldAddEventListener = window.addEventlistener;
var handlers = [];
window.addEventListener = function(event, handler, useCapture) {
handlers.push({ event: event, handler: handler });
oldAddEventListener.call(window, event, handler, useCapture);
};
@jhartikainen
jhartikainen / bot.js
Last active October 20, 2015 10:51
Slack JavaScript REPL bot
var Slack = require('slack-client');
var vm = require('vm');
var s = new Slack('api key here', true, true);
s.on('message', function(msg) {
if(msg.type != 'message') {
return;
}
{-# LANGUAGE NoImplicitPrelude #-}
module Test where
import Language.Fay.Prelude
import Language.Fay.FFI
data Server = Server
{ name :: String
, age :: String
, popstate :: String
@jhartikainen
jhartikainen / segfault.hs
Created September 26, 2012 08:42
Segfault on Ubuntu 12.04 GHC 7.4.1
{-# LANGUAGE BangPatterns #-}
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
import Data.PEM (PEM(..), pemParseBS)
import Data.Certificate.X509
import Data.Either
main :: IO ()
main = do
certdata <- B.readFile "7d0b38bd.0"