Skip to content

Commit

Permalink
tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeBild committed Oct 8, 2012
1 parent c45e96c commit c984bc9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/statemutate.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
function Projections(initial) {
var self = this;
var events = [];
var initialState = initial;
var currentState = initial;
var initialState = initial || '';
var currentState = initial || '';
var projection = function(state, message) { return state; };

self.Message = function(name, payload) {
this.messageName = name || 'DefaultMessageName';
this.payload = payload || '';
}
self.for = function(initial) {
initialState = initial;
currentState = initial;
initialState = initial || '';
currentState = initial || '';
return self;
}
self.append = function(message) {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
},
"main": "./lib/statemutate.js",
"scripts": {
"test": "vows --spec --isolate"
"test": "vows test/* --spec --isolate"
},
"dependencies": {
},
"devDependencies": {
"vows": "0.6.x"
}
"vows": "0.6.x",
"assert" : "0.4.x"
},
"license": "MIT"
}
42 changes: 42 additions & 0 deletions test/specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var vows = require('vows'),
assert = require('assert');

var sm = require('../lib/statemutate.js')

vows.describe('With basic state projection').addBatch({
'When no initital state defined and no elements arranged': {
topic: function () {
var sut = new sm.Projections();
return sut;
},
'we get a empty string as final state': function (topic) {
assert.equal(topic.perform(), '');
}
},
'When a simple initial state and a element added': {
topic: function () {
var sut = new sm.Projections();
sut
.append({
payload: 'tests'
})
.for({
text: ''
})
.with(function(state, message) {
state.text += message.payload;
return state;
})
return sut.perform();
},

'we get other final state': {
'has a final "test" state': function (topic) {
assert.equal(topic.text, 'test');
},
'is not a empty string': function (topic) {
assert.notEqual(topic, '');
}
}
}
}).export(module);

0 comments on commit c984bc9

Please sign in to comment.