Last active
August 29, 2015 14:14
-
-
Save JohnDMathis/80fab3e8300d41ea8835 to your computer and use it in GitHub Desktop.
simple stateful module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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