Skip to content

Instantly share code, notes, and snippets.

Avatar

Gajus Kuizinas gajus

View GitHub Profile
View README.md

File Name

File containing JavaScript must have ".js" extension.

Bad:

index.jsx
@gajus
gajus / gist:d75de7f3fdbfd6486d6a
Created Sep 22, 2014
"Example Factory" a factory method used to instantiate the SUT object with canonical values, overwriting only the properties relevant to the test case.
View gist:d75de7f3fdbfd6486d6a
var SeminarFactory = {
create: function (overwrite) {
var defaultData,
objectData;
defaultData = {
name: 'JavaScript basics',
price: 100
};
View gist:c93f8bac2fe402881916
describe('Seminar', function () {
it('has a name', function () {
var seminar = SeminarFactory.create({name: 'JavaScript'});
expect(seminar.getName()).toEqual('JavaScript');
});
it('has a price', function () {
var seminar = SeminarFactory.create({price: 10});
View gist:2a7fd107f897213aee67
// The hash (#) and dot (.) symbols are a convention to mark if a method
// is called on an individual object or on the prototype. ".create" is
// called on the Cart prototype. #add are called on the derived objects.
describe('Cart', function () {
var cart;
beforeEach(function () {
cart = Cart.create();
});
describe('.create', function () {
View gist:32a61ea65183c4584682
describe('A Cart with a several different products', function () {
var cart;
beforeEach(function () {
cart = Cart.create();
});
it('must have a #grossPriceSum() of the contained products', function () {
var product = Product.create('A', 10),
book = Book.create('B', 100);
View gist:87acb66a7823c2d71c05
describe('Product', function () {
it('must calculate its gross price by adding the VAT', function () {
var product = Product.create('A', 10);
expect(product.grossPrice()).toEqual(12);
});
});
View gist:3591da020955d57ad339
<!DOCTYPE html>
<html ng-app="todoApp">
<head>
<title>First Test</title>
<script src="../angular.js"></script>
<script src="./todo.js"></script>
<style>
.warning { color: #f00; }
.success { color: #0f0; }
View gist:c1be46226fff01736038
<!DOCTYPE html>
<html ng-app="todoApp">
<head>
<title>First Test</title>
<script src="../angular.js"></script>
<script src="./todo.js"></script>
<style>
.warning { color: #f00; }
.success { color: #0f0; }
View gist:8e548c1a8806bd3575a7
<!DOCTYPE html>
<html ng-app="todoApp">
<head>
<title>First Test</title>
<script src="../angular.js"></script>
<script src="./todo.js"></script>
<style>
.warning { color: #f00; }
.success { color: #0f0; }
View gist:7acfd003a44bb1615d2d
var todoApp;
todoApp = angular.module('todoApp', []);
todoApp.controller('TodoController', function ($scope) {
$scope.todo = {
user: 'Adam',
items: [
{name: 'Get the book', done: true},
{name: 'Finish reading the book', done: false},