2. Developers test more than
enough, right?
● Our quality is so high, we don't need to test.
● We don't have dedicated testers
● Our testers find everything just fine.
● Where we're going we don't need roads. -
Doc
3. Manual testing is the way
to go
● They remember to test everything every time
a change is made, right?
● Manual testing is fun, fast, and enjoyable.
8. JasmineJs
BDD for your JavaScript
Jasmine is a behavior-driven development framework for testing your JavaScript code. It does not depend on any other JavaScript
frameworks. It does not require a DOM. And it has a clean, obvious syntax so that you can easily write tests.
describe("Jasmine", function() {
it("makes testing JavaScript awesome!", function() {
expect(yourCode).toBeLotsBetter();
});
});
9. Start Jasmine
(function () {
var jasmineEnv = jasmine.getEnv();
jasmineEnv.updateInterval = 250;
var htmlReporter = new jasmine.HtmlReporter();
jasmineEnv.addReporter(htmlReporter);
jasmineEnv.specFilter = function (spec) {
return htmlReporter.specFilter(spec);
};
var currentWindowOnload = window.onload;
window.onload = function() {
if (currentWindowOnload) {
currentWindowOnload();
}
document.querySelector('.version').innerHTML = jasmineEnv.versionString();
execJasmine();
};
function execJasmine() {
console.log("running jasmine");
jasmineEnv.execute();
}
})();
10. Chai
Assertion framework
var assert = require('chai').assert
, foo = 'bar'
, beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };
assert.typeOf(foo, 'string', 'foo is a string');
assert.equal(foo, 'bar', 'foo equal `bar`');
assert.lengthOf(foo, 3, 'foo`s value has a length of 3');
assert.lengthOf(beverages.tea, 3, 'beverages has 3 types
of tea');
Or
var expect = require('chai').expect
, foo = 'bar'
, beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };
expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.length(3);
expect(beverages).to.have.property('tea').with.length(3);
Or
var should = require('chai').should() //actually call the
the function
, foo = 'bar'
, beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };
foo.should.be.a('string');
foo.should.equal('bar');
foo.should.have.length(3);
beverages.should.have.property('tea').with.length
(3);
11. PhantomJs
Is your automated testing not quite fast
enough?
Automated testing tools not quite extensible
enough?
Try PhantomJs
Full web stack
No browser required
12. Phantom Barebones
example
console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://www.phantomjs.org/';
page.open(url, function (status) {
//Page is loaded!
phantom.exit();
});
13. Phantom Sample Post
// Example using HTTP POST operation
var page = require('webpage').create(),
server = 'http://posttestserver.com/post.php?dump',
data = 'universe=expanding&answer=42';
page.open(server, 'post', data, function (status) {
if (status !== 'success') {
console.log('Unable to post!');
} else {
console.log(page.content);
}
phantom.exit();
});
18. My Chai (not Mai-Tai)
bAssert(function(){ assert.typeOf('test','string','test is a string');});
bAssert(function(){
var currentItemIndex=page.evaluate(function(){
return $('.first-index:first').text();
});
console.log('currentItemIndex='+currentItemIndex);
assert.notEqual(currentItemIndex,'','current item index should never be empty');
});