Skip to content

Instantly share code, notes, and snippets.

@andrepadez
Created January 5, 2015 15:17
Show Gist options
  • Save andrepadez/b33797db10eea035d38b to your computer and use it in GitHub Desktop.
Save andrepadez/b33797db10eea035d38b to your computer and use it in GitHub Desktop.
tests - old and new
var Dog = function(name, age){
if(!name || !age){
throw new Error('not enough params');
}
this.name = name;
this.age = age;
}
///////////////////////////
var Dog;
var a, b;
goog.require('path.to.difjh.sdfihsdkjfhsd.dog');
function setupPage(){
Dog = path.to.difjh.sdfihsdkjfhsd.dog;
}
function teardownPage(){
window.Dog = null;
}
function setup(){
a = new Dog('fido', 3);
b = new Dog('fido', 2);
}
function teardown(){
a.destroy();
b.destroy();
}
function constructorTest(){
var newObj = new Dog('fido', 3);
}
function sameNameTest(){
assert.equal(a.name, b.name);
}
function differentAgeTest(){
assert.notEqual(a.age, b.age);
}
//////////////////////////////////
var assert = chai.assert;
var Dog;
var a, b;
goog.require('path.to.difjh.sdfihsdkjfhsd.dog');
describe('we are testing the class DOG', function(){
before(function(){
Dog = path.to.difjh.sdfihsdkjfhsd.dog;
});
after(function(){
window.Dog = null;
});
beforeEach(function(){
a = new Dog('fido', 3);
b = new Dog('fido', 2);
});
afterEach(function(){
a.destroy();
b.destroy();
});
it('should be able to create an object', function(){
var newObj = new Dog('scooby', 3);
});
it('should break if no age', function(){
assert.throws(function(){
var newObj = new Dog('scooby');
}, 'not enough params');
});
it('should break if no name', function(){
assert.throws(function(){
var newObj = new Dog(null, 10);
}, 'not enough params');
});
it('should be different objects with the same name', function(){
assert.equal(a.name, b.name);
})
it('should be different objects with different ages', function(){
assert.notEqual(a.age, b.age);
});
it('should create on Timeout(async)', function(done){
setTimeout(function(){
assert.equal(a.name, b.name);
done();
}, 1000);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment