@@ -148,6 +148,38 @@ test("innapropriate events", function() {
148148
149149//-----------------------------------------------------------------------------
150150
151+ test ( "inappropriate event handling can be customized" , function ( ) {
152+
153+ var fsm = StateMachine . create ( {
154+ error : function ( eventName ) {
155+ return 'event ' + eventName + ' inappropriate in current state ' + this . current ;
156+ } ,
157+ initial : 'green' ,
158+ events : [
159+ { name : 'warn' , from : 'green' , to : 'yellow' } ,
160+ { name : 'panic' , from : 'yellow' , to : 'red' } ,
161+ { name : 'calm' , from : 'red' , to : 'yellow' }
162+ ] } ) ;
163+
164+ equals ( fsm . current , 'green' , "initial state should be green" ) ;
165+
166+ equals ( fsm . panic ( ) , 'event panic inappropriate in current state green' ) ;
167+ equals ( fsm . calm ( ) , 'event calm inappropriate in current state green' ) ;
168+
169+ fsm . warn ( ) ;
170+ equals ( fsm . current , 'yellow' , "current state should be yellow" ) ;
171+ equals ( fsm . warn ( ) , 'event warn inappropriate in current state yellow' ) ;
172+ equals ( fsm . calm ( ) , 'event calm inappropriate in current state yellow' ) ;
173+
174+ fsm . panic ( ) ;
175+ equals ( fsm . current , 'red' , "current state should be red" ) ;
176+ equals ( fsm . warn ( ) , 'event warn inappropriate in current state red' ) ;
177+ equals ( fsm . panic ( ) , 'event panic inappropriate in current state red' ) ;
178+
179+ } ) ;
180+
181+ //-----------------------------------------------------------------------------
182+
151183test ( "event is cancelable" , function ( ) {
152184
153185 var fsm = StateMachine . create ( {
0 commit comments