Skip to content

Instantly share code, notes, and snippets.

Avatar
🐵
🚀 🤖

Jade Dominguez plusjade

🐵
🚀 🤖
View GitHub Profile
@plusjade
plusjade / jasmine-this-vars.md
Created Dec 19, 2015 — forked from traviskaufman/jasmine-this-vars.md
Better Jasmine Tests With `this`
View jasmine-this-vars.md

Better Jasmine Tests With this

On the Refinery29 Mobile Web Team, codenamed "Bicycle", all of our unit tests are written using Jasmine, an awesome BDD library written by Pivotal Labs. We recently switched how we set up data for tests from declaring and assigning to closures, to assigning properties to each test case's this object, and we've seen some awesome benefits from doing such.

The old way

Up until recently, a typical unit test for us looked something like this:

describe('views.Card', function() {
View gist:541645bbbdfe8f2bfd3e
Started GET "/api/v2/searches/autocomplete_term?source=web&warehouse_id=5&zone_id=9" for ::1 at 2015-03-16 13:54:41 -0700
Processing by Api::V2::SearchesController#autocomplete_term as JSON
Parameters: {"source"=>"web", "warehouse_id"=>"5", "zone_id"=>"9"}
View blah.html
<form action="/friends" method="POST">
<input type="text" name="lastname">
<button type="submit">Submit</button>
</form>
@plusjade
plusjade / track-score.html
Created Feb 18, 2015
track a score using a variable
View track-score.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var score = 0;
function computeScore(outcome) {
if(outcome) {
@plusjade
plusjade / random.html
Created Feb 18, 2015
randomize an array
View random.html
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
</head>
<body>
<script>
var numbers = [1,2,3,4,5,6,7,8,9];
var randomNumbers = _.shuffle(numbers, numbers.length);
View cheatsheet.js
/* -----------------------------------------------------------------------------
INTERACTING WITH THE USER INTERFACE
------------------------------------------------------------------------------*/
// GET HTML (DOM) ELEMENT
// I need to reference an HTML element inside javascript:
View todo-list.html
<h4>Todo List</h4>
<form>
<input name="item">
<button type="submit">Add Item</button>
</form>
<ul id="todo-items">
<li>Item 1 <button>x</button></li>
<li>Item 2 <button>x</button></li>
<li>Item 3 <button>x</button></li>
</ul>
View react-todo.html
<div id="todo"></div>
<script src="//cdnjs.cloudflare.com/ajax/libs/react/0.12.2/react.min.js"></script>
<script>
Todo = React.createClass({
displayName: 'Todo'
,
getInitialState : function() {
return { items: [] };
}
View state.json
"user" : {
"name" : "John Smith",
"quota" : 100,
"_type" : "Administrator"
}
View index.html
<form>
<input name="item">
<button type="submit">Add Item</button>
</form>
<ul id="todo-items">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
You can’t perform that action at this time.