This file contains hidden or 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
require("buster"); | |
var my = require("../lib/my.js"); | |
buster.testCase("A module", { | |
"states the obvious": function () { | |
assert.equals(my.double(5), "10", "Should double the number"); | |
}, | |
"we need a funny failing test also": function () { | |
assert.same(my.double(5), "10", "Should double the number"); | |
} | |
}); |
This file contains hidden or 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
exports.double = function (tall) { | |
return tall * doubler; | |
}; |
This file contains hidden or 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
buster.testCase("The ViewModel", { | |
"should update the fullname when firstname changes": function () { | |
var vm = new AppViewModel(); | |
vm.firstName("Arne"); | |
assert.equals(vm.fullName(), "Arne Bertington"); | |
}, | |
"should capitalize the last name when capitalizeLastName is called": function () { | |
var vm = new AppViewModel(); | |
vm.firstName("Arne"); | |
vm.capitalizeLastName(); |
This file contains hidden or 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
function AppViewModel() { | |
var self = this; | |
self.firstName = ko.observable("Bert"); | |
self.lastName = ko.observable("Bertington"); | |
self.fullName = ko.computed(function () { | |
return self.firstName() + " " + self.lastName(); | |
}, self); | |
self.capitalizeLastName = function () { |
This file contains hidden or 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
buster.testCase("The ViewModel", { | |
"setUp": function () { | |
this.vm = new ReservationsViewModel(); | |
}, | |
"total sum should be zero when initialized": function () { | |
assert.same(this.vm.totalSurcharge(), 0); | |
}, | |
"total number of seats should be two": function () { | |
assert.same(this.vm.seats().length, 2); | |
}, |
This file contains hidden or 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
function SeatReservation(name, initialMeal) { | |
var self = this; | |
self.name = name; | |
self.meal = ko.observable(initialMeal); | |
self.formattedPrice = ko.computed(function () { | |
var price = self.meal().price; | |
return price ? "$" + price.toFixed(2) : "None"; | |
}); | |
} |
This file contains hidden or 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
// Overall viewmodel for this screen, along with initial state | |
function ReservationsViewModel() { | |
var self = this; | |
// Non-editable catalog data - would come from the server | |
self.availableMeals = [ | |
{ mealName: "Standard (sandwich)", price: 0 }, | |
{ mealName: "Premium (lobster)", price: 34.95 }, | |
{ mealName: "Ultimate (whole zebra)", price: 290 } | |
]; |
This file contains hidden or 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
"use strict"; | |
buster.testCase("The ViewModel", { | |
"setUp": function () { | |
// Spying on existing method | |
this.spy(MYAPP.services, 'load'); | |
this.vm = new TaskListViewModel(); | |
}, | |
"load should be called on initialization": function () { | |
assert.calledOnce(MYAPP.services.load); | |
}, |
This file contains hidden or 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
"use strict"; | |
function Task(data) { | |
this.title = ko.observable(data.title); | |
this.isDone = ko.observable(data.isDone); | |
} | |
function TaskListViewModel() { | |
// Data | |
var self = this; |
This file contains hidden or 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
"use strict"; | |
buster.testCase("The ViewModel", { | |
"setUp": function () { | |
// Spying on existing method | |
this.spy(MYAPP.services, 'load'); | |
this.vm = new TaskListViewModel(); | |
}, | |
"load should be called on initialization": function () { | |
assert.calledOnce(MYAPP.services.load); | |
}, |
OlderNewer