Permalink
Browse files

Throwing sensible error when calling stateSwitch without a stateName

  • Loading branch information...
nvh committed Oct 6, 2016
1 parent 554908c commit e5584aca5264a7abaa3d85af9700e7ed89b36872
Showing with 8 additions and 1 deletion.
  1. +3 −1 framer/Layer.coffee
  2. +5 −0 test/tests/LayerStatesTest.coffee
View
@@ -903,7 +903,7 @@ class exports.Layer extends BaseClass
# Support options as an object
options = options.options if options.options?
-
+
return @states.machine.switchTo(stateName, options)
# Support the old properties syntax, we add all properties top level and
@@ -935,6 +935,8 @@ class exports.Layer extends BaseClass
@animate(@states.machine.next(states), options)
stateSwitch: (stateName, options={}) ->
+ unless stateName?
+ throw new Error("Missing required argument 'stateName' in stateSwitch()")
return @animate(stateName, options) if options.animate is true
return @animate(stateName, _.defaults({}, options, {instant:true}))
@@ -602,6 +602,11 @@ describe "LayerStates", ->
layer.x.should.equal 400
layer.states.current.name.should.equal "testB"
+ it "should throw an error when called without a stateName", ->
+ layer = new Layer
+ layer.states.testA = {x: 200}
+ expect(-> layer.stateSwitch()).to.throw("Missing required argument 'stateName' in stateSwitch()")
+
describe "Options", ->
it "should listen to layer.options", ->

0 comments on commit e5584ac

Please sign in to comment.