Skip to content

Commit

Permalink
coverage for _new_state/1 and machine_state/0
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Jul 5, 2017
1 parent 09ed3cc commit e3212a8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
4 changes: 3 additions & 1 deletion dist/jssm.es5.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/lib/index.html
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset='utf-8' />
<title>jssm 2.9.14 | Documentation</title>
<title>jssm 2.9.16 | Documentation</title>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' type='text/css' rel='stylesheet' />
<link href='assets/style.css' type='text/css' rel='stylesheet' />
Expand All @@ -14,7 +14,7 @@
<div class='fixed xs-hide fix-3 overflow-auto max-height-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>jssm</h3>
<div class='mb1'><code>2.9.14</code></div>
<div class='mb1'><code>2.9.16</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jssm",
"version": "2.9.14",
"version": "2.9.16",
"engines": {
"node": ">=6.0.0"
},
Expand Down
7 changes: 6 additions & 1 deletion src/js/jssm.js
Expand Up @@ -148,9 +148,14 @@ class machine<mNT, mDT> {
}

_new_state(state_config : JssmGenericState<mNT>) : mNT { // whargarbl get that state_config any under control
if (this._states.has(state_config.name)) { throw new Error(`state ${(state_config.name:any)} already exists`); }

if (this._states.has(state_config.name)) {
throw new Error(`state ${(state_config.name:any)} already exists`);
}

this._states.set(state_config.name, state_config);
return state_config.name;

}


Expand Down
30 changes: 30 additions & 0 deletions src/js/tests/general.js
Expand Up @@ -402,6 +402,21 @@ describe('reports on states', async it => {



describe('returns states', async it => {

const machine = new jssm.machine({
initial_state: 'off',
transitions:[ { name:'turn_on', action:'power_on', from:'off', to:'red'} ]
});

it('that it has', t => t.is('object', typeof machine.machine_state() ) );

});





describe('reports on transitions', async it => {

const machine = new jssm.machine({
Expand Down Expand Up @@ -549,4 +564,19 @@ describe('Illegal machines', async it => {
}, Error));


it('internal state helper must not accept double states', t => t.throws(() => {

const machine = new jssm.machine({
initial_state: 'moot',
transitions:[
{ name:'id1', from:'1', to:'2', action:'identical' }
]
});

machine._new_state({from: '1', name:'id1', to:'2', complete:false});
machine._new_state({from: '1', name:'id1', to:'2', complete:false});

}, Error));


});

0 comments on commit e3212a8

Please sign in to comment.