Skip to content

Instantly share code, notes, and snippets.

@JohnDMathis
Last active August 29, 2015 14:14
Show Gist options
  • Save JohnDMathis/80fab3e8300d41ea8835 to your computer and use it in GitHub Desktop.
Save JohnDMathis/80fab3e8300d41ea8835 to your computer and use it in GitHub Desktop.
simple stateful module
var state = {
foo: 'bam'
};
function getState() {
return this;
}
function setBoo() {
this.foo = "boo";
}
function setVar( x ) {
this.foo = x;
}
var wrapper = {
getState: getState.bind( state ),
setBoo: setBoo.bind( state ),
setVar: setVar.bind( state )
};
module.exports = wrapper;
require( 'should' );
describe( "test", function() {
var test;
before( function() {
test = require( './test.js' );
} );
describe( "getState", function() {
var s;
before( function() {
s = test.getState();
} );
it( 'returns state', function() {
s.should.have.property( 'foo' );
s.foo.should.equal( 'bam' );
} );
} );
describe( "setBoo", function() {
var s;
before( function() {
test.setBoo();
} );
it( 'says boo', function() {
s = test.getState();
s.foo.should.equal( 'boo' );
} );
} );
describe( "setState", function() {
var s;
before( function() {
test.setVar( 'whoop' );
} );
it( 'says whoop', function() {
s = test.getState();
s.foo.should.equal( 'whoop' );
} );
} );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment