Skip to content

Instantly share code, notes, and snippets.

View gajus's full-sized avatar

Gajus Kuizinas gajus

View GitHub Profile
@gajus
gajus / README.md
Last active August 28, 2015 07:08

File Name

File containing JavaScript must have ".js" extension.

Bad:

index.jsx
@gajus
gajus / gist:d75de7f3fdbfd6486d6a
Created September 22, 2014 08:28
"Example Factory" a factory method used to instantiate the SUT object with canonical values, overwriting only the properties relevant to the test case.
var SeminarFactory = {
create: function (overwrite) {
var defaultData,
objectData;
defaultData = {
name: 'JavaScript basics',
price: 100
};
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});
// 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 () {
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);
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);
});
});
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},
<!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; }
<!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; }
<!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; }