Skip to content

Instantly share code, notes, and snippets.

@jkimbo
Created March 24, 2015 18:23
Show Gist options
  • Save jkimbo/b53e502c9f135e0ffd05 to your computer and use it in GitHub Desktop.
Save jkimbo/b53e502c9f135e0ffd05 to your computer and use it in GitHub Desktop.
Mocha testing with gulp
gulp.task('test', function(cb) {
var mocha = require('gulp-mocha');
var React = require('react-tools');
global.initDOM = function() {
var jsdom = require('jsdom');
global.window = jsdom.jsdom().createWindow('<html><body></body></html>');
global.document = global.window.document;
global.navigator = global.window.navigator;
for (var i in require.cache) {
delete require.cache[i];
}
};
global.cleanDOM = function() {
delete global.window;
delete global.document;
delete global.navigator;
};
// Allows us to import .jsx files without going through browserify
require('node-jsx').install({extension: '.jsx', harmony: true});
require.extensions['.js'] = function(module, filename) {
var src = fs.readFileSync(filename, {encoding: 'utf8'});
if (!(/node_modules/.test(filename))) {
src = React.transform(src, { harmony: true });
}
module._compile(src, filename);
};
var reporter = gulp.env.reporter || 'spec';
gulp.src(['**/__tests__/**/*.js', '**/__tests__/**/*.jsx'])
.pipe(mocha({
reporter: reporter,
grep: gulp.env.filter,
}))
.on('end', cb);
});
/* global describe, it, beforeEach, afterEach */
"use strict";
require('should');
var Fluxxor = require('fluxxor');
function noop() {}
function setUpFlux(config) {
var Store = require('../store');
var Actions = require('../../actions');
var actions = new Actions(config);
var stores = {
Store: new Store(config)
};
var flux = new Fluxxor.Flux(stores, actions);
return flux;
}
describe("Test store", function() {
it("responds to action", function() {
var flux = setUpFlux();
(flux.stores.Store.foo).should.equal(false);
flux.actions.setFoo();
(flux.stores.Store.foo).should.equal(true);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment