Skip to content

Instantly share code, notes, and snippets.

View plusjade's full-sized avatar
🐵
🚀 🤖

Jade Dominguez plusjade

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

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() {
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"}
<form action="/friends" method="POST">
<input type="text" name="lastname">
<button type="submit">Submit</button>
</form>
@plusjade
plusjade / track-score.html
Created February 18, 2015 01:57
track a score using a variable
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
var score = 0;
function computeScore(outcome) {
if(outcome) {
@plusjade
plusjade / random.html
Created February 18, 2015 01:53
randomize an array
<!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);
/* -----------------------------------------------------------------------------
INTERACTING WITH THE USER INTERFACE
------------------------------------------------------------------------------*/
// GET HTML (DOM) ELEMENT
// I need to reference an HTML element inside javascript:
<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>
<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: [] };
}
"user" : {
"name" : "John Smith",
"quota" : 100,
"_type" : "Administrator"
}
<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>