Difference between revisions of "Testing"
From Wiki2
(Created page with "===testing=== http://jsfiddle.net/fdietz/2Ny8x/") |
|||
Line 2: | Line 2: | ||
http://jsfiddle.net/fdietz/2Ny8x/ | http://jsfiddle.net/fdietz/2Ny8x/ | ||
npm install mocha chai --save-dev | |||
same as | |||
npm i -D mocha chai | |||
create a test file src/index.test.js | |||
var expect = require('chai').expect; | |||
var starWars = require('./index'); | |||
describe('starwars-names', function() { | |||
describe('all', function() { | |||
it('should be an array of strings', function() { | |||
expect(starWars.all).to.satisfy(isArrayOfStrings); | |||
function isArrayOfStrings(array) { | |||
return array.every(function(item) { | |||
return typeof item === 'string'; | |||
}); | |||
} | |||
}); | |||
it('should contain `Luke Skywalker`', function() { | |||
expect(starWars.all).to.include('Luke Skywalker'); | |||
}); | |||
}); | |||
describe('random', function() { | |||
it('should return a random item from the starWars.all', function() { | |||
var randomItem = starWars.random(); | |||
expect(starWars.all).to.include(randomItem); | |||
}); | |||
}); | |||
}); | |||
change package.json to run tests (automatically on update -w) | |||
"scripts": { | |||
"test": "mocha src/index.test.js -w" | |||
}, | |||
npm test |
Revision as of 10:55, 20 November 2015
testing
http://jsfiddle.net/fdietz/2Ny8x/
npm install mocha chai --save-dev
same as npm i -D mocha chai
create a test file src/index.test.js
var expect = require('chai').expect; var starWars = require('./index'); describe('starwars-names', function() { describe('all', function() { it('should be an array of strings', function() { expect(starWars.all).to.satisfy(isArrayOfStrings); function isArrayOfStrings(array) { return array.every(function(item) { return typeof item === 'string'; }); } }); it('should contain `Luke Skywalker`', function() { expect(starWars.all).to.include('Luke Skywalker'); }); }); describe('random', function() { it('should return a random item from the starWars.all', function() { var randomItem = starWars.random(); expect(starWars.all).to.include(randomItem); }); }); });
change package.json to run tests (automatically on update -w)
"scripts": { "test": "mocha src/index.test.js -w" },
npm test