File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 33import { StateDeclaration , StateOrName , TargetStateDef } from './interface' ;
44import { TransitionOptions } from '../transition/interface' ;
55import { StateObject } from './stateObject' ;
6- import { isString } from '../common/predicates' ;
6+ import { isObject , isString } from '../common/predicates' ;
77import { stringify } from '../common/strings' ;
88import { extend } from '../common' ;
99import { StateRegistry } from './stateRegistry' ;
@@ -44,7 +44,9 @@ export class TargetState {
4444 private _options : TransitionOptions ;
4545
4646 /** Returns true if the object has a state property that might be a state or state name */
47- static isDef = ( obj ) : obj is TargetStateDef => obj && obj . state && ( isString ( obj . state ) || isString ( obj . state . name ) ) ;
47+ static isDef = ( obj ) : obj is TargetStateDef => {
48+ return obj && obj . state && ( isString ( obj . state ) || ( isObject ( obj . state ) && isString ( obj . state . name ) ) ) ;
49+ } ;
4850
4951 /**
5052 * The TargetState constructor
Original file line number Diff line number Diff line change @@ -28,6 +28,18 @@ describe('TargetState object', function() {
2828 expect ( ref . error ( ) ) . toBe ( "No such state 'notfound'" ) ;
2929 } ) ;
3030
31+ describe ( '.isDef' , function ( ) {
32+ it ( 'should return true for TargetStateDef objects' , ( ) => {
33+ expect ( TargetState . isDef ( { state : 'foo' } ) ) . toBeTrue ( ) ;
34+ expect ( TargetState . isDef ( { state : { name : 'foo' } } ) ) . toBeTrue ( ) ;
35+ } ) ;
36+
37+ it ( 'should return false for TargetState instances' , ( ) => {
38+ const ref = new TargetState ( registry , 'foo' ) ;
39+ expect ( TargetState . isDef ( ref ) ) . toBeFalse ( ) ;
40+ } ) ;
41+ } ) ;
42+
3143 describe ( '.withState' , function ( ) {
3244 it ( 'should replace the target state' , ( ) => {
3345 const ref = new TargetState ( registry , 'foo' ) ;
You can’t perform that action at this time.
0 commit comments