View gist:889f3843ba8299677f21de16afcbb882
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//guess where this fails. | |
this.x = function() { | |
hello(); | |
} | |
(foo || bar).call(); |
View lol.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//java | |
class X extends Y { | |
public X() { | |
super(); | |
} | |
public void method() { | |
} | |
public static staticMethod() { |
View test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//easy way to check if object has the expected "shape": | |
it('tests something', function() { | |
var expectedObject = { | |
some: 'prop', | |
values: 'here' | |
}; | |
var result = doStuff(); | |
assert.deepEqual(result, expectedObject); |
View timeouts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var moves = [].. | |
function makeMove() { | |
var m = moves.shift(); | |
if(!m) { | |
return everythingDone(); | |
} | |
setTimeout(function() { | |
activateButton(m); |
View chain.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//let's say all the moves are in this array | |
var moves = [...]; | |
moves.reduce(function(p, move) { | |
return p.then(activateWithDelay(move.button)) | |
.then(deactivateWithDelay(move.button)); | |
}, Promise.resolve()); |
View foo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
View paramTest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}) | |
}); |
View foo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
someModule.service('something', function($rootScope) { | |
var emitter = $rootScope.$new(true); | |
var data = whateverStuffHere; | |
return { | |
onDataUpdated: function(callback) { | |
//by returning the result from $on, we get | |
//the ability to remove event listeners easily | |
return emitter.$on('update', callback); |
View tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('something', function() { | |
var oldXrm; | |
beforeEach(function() { | |
oldXrm = Xrm; | |
Xrm = { | |
Page: { | |
getAttribute: sinon.stub() | |
} | |
}; |
View sandbox.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('something', function() { | |
var sandbox; | |
beforeEach(function() { | |
sandbox = sinon.sandbox.create(); | |
}); | |
afterEach(function() { | |
sandbox.restore(); | |
}); | |
NewerOlder