File tree 2 files changed +16
-2
lines changed
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 3
3
import { StateDeclaration , StateOrName , TargetStateDef } from './interface' ;
4
4
import { TransitionOptions } from '../transition/interface' ;
5
5
import { StateObject } from './stateObject' ;
6
- import { isString } from '../common/predicates' ;
6
+ import { isObject , isString } from '../common/predicates' ;
7
7
import { stringify } from '../common/strings' ;
8
8
import { extend } from '../common' ;
9
9
import { StateRegistry } from './stateRegistry' ;
@@ -44,7 +44,9 @@ export class TargetState {
44
44
private _options : TransitionOptions ;
45
45
46
46
/** 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
+ } ;
48
50
49
51
/**
50
52
* The TargetState constructor
Original file line number Diff line number Diff line change @@ -28,6 +28,18 @@ describe('TargetState object', function() {
28
28
expect ( ref . error ( ) ) . toBe ( "No such state 'notfound'" ) ;
29
29
} ) ;
30
30
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
+
31
43
describe ( '.withState' , function ( ) {
32
44
it ( 'should replace the target state' , ( ) => {
33
45
const ref = new TargetState ( registry , 'foo' ) ;
You can’t perform that action at this time.
0 commit comments