Skip to content

Instantly share code, notes, and snippets.

View MandarinConLaBarba's full-sized avatar

Mandarin Drummond MandarinConLaBarba

View GitHub Profile
@MandarinConLaBarba
MandarinConLaBarba / test-mock.js
Created May 15, 2012 22:03
Jasmine Spies: Mocking
var testModule = require("./testModule"),
testModule2 = require('./testModule2');
describe("mock/spy test", function() {
it("should not pass", function(done) {
var theNewValue = "this is a mock, sucker!"
@MandarinConLaBarba
MandarinConLaBarba / gist:4533303
Last active December 31, 2021 22:24
How to spy on node's require() w/ sinon.js
//If you need to spy or stub the global require function in node.js, don't try to spy on the require function itself..you aren't going //to be successful.
//Instead, spy on the require.extensions object like so:
var spies = {};
spies.require = sinon.spy(require.extensions, '.js');
//Then when you need to assert you can do stuff like:
spies.require.firstCall.args[1].should.include("path/to/some/module");
@MandarinConLaBarba
MandarinConLaBarba / gist:5055681
Created February 28, 2013 10:16
Sebastian first example
sebastian.flow("flows.examples.first")
.step("one", function() {
console.log("Welcome...");
})
.step("two", function() {
console.log("...to Sebastian.");
})
.begin();
var userName = view.$el.find('#txtUserName').val(),
password = view.$el.find('#txtPassword').val();
$.when(user.login())
.done(function() {
$.when(user.fetch())
.done(function() {
if (user.get("isAdmin")) {
view.showAdminPanel();
}
sebastian.flow("flows.examples.splash")
.step("get-form-data", function() {
var userName = this.view.$el.find('#txtUserName').val(),
password = this.view.$el.find('#txtPassword').val();
return $.Deferred().resolve(userName, password);
})
.step("login-user", function(userName, password) {
this.user.set("userName", userName);
describe("flows.example.splash", function() {
describe("steps", function() {
describe("login-user", function() {
beforeEach(function() {
//Get the step
var target = sebastian.flow("flows.example.splash").step("login-user"),
(function(root, enqueue) {
// Set up appropriately for the environment.
if (typeof exports !== 'undefined') {
// Node/CommonJS, need jQuery-deferred instead of regular jQuery
enqueue(
require('jquery-deferred'),
require("underscore"),
require('sinon'),
require('should'),
require('../sebastian').flow);
// base path, that will be used to resolve files and exclude
basePath = '';
// list of files / patterns to load in the browser
files = [
MOCHA,
MOCHA_ADAPTER,
REQUIRE,
REQUIRE_ADAPTER,
require.config({
"baseUrl" : "/base",
//paths to the stuff Testacular has loaded into the server, but not included in the page
"paths" : {
"jquery" : "vendor/jquery/jquery",
"chai" : "vendor/chai/chai",
"underscore" : "vendor/underscore-amd/underscore",
"sinon" : "vendor/sinon/sinon"
},
//Some shims..
mandarin@Tyrell:~/code/sebastian>mocha test/index.js
․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․․
✔ 66 tests complete (53 ms)