describe('numberAdder', function() {
it('adds numbers', function() {
var result = numberAdder(1, 3);
assert.equal(result, 4);
});
});
describe('SmartMaths', function() {
describe('numberAdder', function() {
it('adds numbers', function() {
var result = SmartMaths.numberAdder(1, 3);
assert.equal(result, 4);
});
});
});
describe('SmartMaths', function() {
describe('numberAdder', function() {
it('adds numbers', function(done) {
SmartMaths.numberAdder(1, 3, function(err, result) {
assert.equal(err, null);
assert.equal(result, 4);
done();
});
});
});
});
describe('numberAdder', function() {
it.only('adds numbers', function(done) {
...
});
it.skip("doesn't add strings", function(done) {
...
});
});
describe('numberAdder', function() {
beforeEach(function() {
this.lookup = mathsDb.lookup;
mathsDb.lookup = function(a, b, callback) {
assert.equal(a, 1);
assert.equal(b, 3);
callback(4);
}
});
afterEach(function() {
mathsDb.lookup = this.lookup;
});
it('adds numbers', function(done) {
...
});
});
describe('numberAdder', function() {
beforeEach(function() {
this.lookup = mathsDb.lookup;
mathsDb.lookup = function(a, b, callback) {
assert.equal(a, 1);
assert.equal(b, 3);
callback(4);
}
});
afterEach(function() {
mathsDb.lookup = this.lookup;
});
it('adds numbers', function(done) {
...
});
});
describe('numberAdder', function() {
beforeEach(function() {
sinon.stub(mathsDb, 'lookup').calledWith(1, 3).yields(4);
});
afterEach(function() {
mathsDb.lookup.restore();
});
it('adds numbers', function(done) {
assert(mathsDb.lookup.calledOnce);
...
});
});
describe('numberAdder', function() {
beforeEach(function() {
this.sinon = sinon.sandbox.create();
this.sinon.stub(mathsDb, 'lookup').calledWith(1, 3).yields(4);
});
afterEach(function() {
this.sinon.restore();
});
it('adds numbers', function(done) {
assert(mathsDb.lookup.calledOnce);
...
});
});
// gulpfile.js
var gulp = require('gulp');
var uglify = require('gulp-uglify');
gulp.task('compress', function() {
return gulp.src(['lib/**/*.js', '!lib/jquery-lol.js'])
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
$ gulp compress
[13:19:38] Using gulpfile ~/projects/mouserat/gulpfile.js
[13:19:38] Starting 'compress'...
[13:19:39] Finished 'compress' after 150 ms
var gulp = require('gulp');
var mocha = require('gulp-mocha');
gulp.task('test', function() {
return gulp.src(['test/server/**/*.js']).pipe(mocha());
});
var gulp = require('gulp');
var karma = require('gulp-karma');
gulp.task('test-client', function(cb) {
return gulp.src(['public/js/**/*.js', 'test/client/**/*.js'])
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', cb);
});
// karma.conf.js
module.exports = function(config) {
config.set({
browsers: ['Chrome', 'PhantomJS'],
frameworks: ['mocha']
});
};
beforeEach(module('ThingController'));
beforeEach(inject(function($rootScope, $controller, $http) {
this.$controller = $controller;
this.$scope = $rootScope.$new();
$controller('dashboard', {
$scope: this.$scope,
$http: $http
});
});
it('should set a welcome message', function(){
assert.equal(this.$scope.text, 'Hello World!');
});
// app.js
var request = require('supertest');
var app = require('express')();
var controllers = {
user: function(req, res) {
res.send(200, {});
}
}
app.get('/user', controllers);
describe('GET /user', function() {
beforeEach(function() {
sinon.spy(controllers, 'user')
});
it('responds correctly', function(done) {
request(app)
.get('/user')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, function(err) {
assert(controllers.user.calledOnce);
done(err);
});
});
});
var protractor = require("gulp-protractor").protractor;
gulp.task('acceptance', function(cb) {
return gulp.src(["test/acceptance/**/*.js"])
.pipe(protractor({
configFile: "protractor.config.js",
args: ['--baseUrl', 'http://localhost:3000']
}));
});
// protractor.config.js
exports.config = {
framework: 'mocha',
seleniumServerJar: 'selenium-server-standalone.jar'
};
var chai = require('chai');
chai.use(require('chai-as-promised'));
describe('the homepage', function() {
it('should allow you to write a message', function() {
browser.get('');
element(by.model('message')).sendKeys("Ima typing ma keyboard");
element(by.css('[value="add"]')).click();
element(by.id('button')).click();
var messages = element.all(by.repeater('message in messages'));
chai.expect(messages.count()).to.eventually.equal(0);
chai.expect(messages.get(0).getText()).to.eventually.equal("Ima typing ma keyboard");
});
});
var protractor = require("gulp-protractor").protractor;
gulp.task('smoke', function(cb) {
return gulp.src(["test/acceptance/**/*.js"])
.pipe(protractor({
configFile: "protractor.config.js",
args: ['--baseUrl', 'http://www.bensmindpalace.co.uk']
}));
});
var gulp = require('gulp');
var gulpIstanbul = require('gulp-istanbul');
gulp.task('coverage', function(cb) {
return gulp.src(['lib/**/*.js'])
.pipe(gulpIstanbul({ includeUntested: true }))
.pipe(gulpIstanbul.hookRequire())
.on('end', function() {
gulp.src(['test/lib/**/*.js'])
.pipe(mocha())
.on('error', cb)
.pipe(gulpIstanbul.writeReports({ reporters: ['lcov', 'text-summary'] }))
.pipe(gulpIstanbul.enforceThresholds({ thresholds: { global: 1 }}))
.on('error', cb);
});
});