From 3cd7bd6ae00a649a063a96ca21688a6fd2012450 Mon Sep 17 00:00:00 2001 From: David Khourshid Date: Mon, 23 Apr 2018 08:34:51 -0400 Subject: [PATCH] Ensuring matchesState returns false when parent is more specific than child. Fixes #69 --- src/graph.ts | 4 ++-- src/matchesState.ts | 3 ++- test/matchesState.test.ts | 11 +++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/graph.ts b/src/graph.ts index 73db99af78..6f686aab85 100644 --- a/src/graph.ts +++ b/src/graph.ts @@ -1,5 +1,5 @@ import { StateNode } from './index'; -import { toStateValue } from './utils'; +import { toStateValue, getActionType } from './utils'; import { StateValue, Machine, @@ -37,7 +37,7 @@ function getEventEdges(node: StateNode, event: string): Edge[] { source: node, target: node.parent!.getState(transition.target)!, event, - actions: transition.actions || [], + actions: transition.actions ? transition.actions.map(getActionType) : [], cond: transition.cond }; }); diff --git a/src/matchesState.ts b/src/matchesState.ts index 68e003cdcc..92b9a59f5a 100644 --- a/src/matchesState.ts +++ b/src/matchesState.ts @@ -15,7 +15,8 @@ export function matchesState( return childStateValue === parentStateValue; } - return childStateValue in parentStateValue; + // Parent more specific than child + return false; } if (typeof parentStateValue === 'string') { diff --git a/test/matchesState.test.ts b/test/matchesState.test.ts index 82c82ca209..a8d60227a9 100644 --- a/test/matchesState.test.ts +++ b/test/matchesState.test.ts @@ -60,12 +60,11 @@ describe('matchesState()', () => { assert.ok(!matchesState('a.a1', 'b.b1')); }); - xit( - 'should return false if parent state is more specific than child state', - () => { - assert.ok(!matchesState('a.b.c', 'a.b')); - } - ); + it('should return false if parent state is more specific than child state', () => { + assert.ok(!matchesState('a.b.c', 'a.b')); + + assert.ok(!matchesState({ a: { b: { c: 'd' } } }, { a: 'b' })); + }); it('should return false if two state values are not equivalent', () => { assert.ok(!matchesState({ a: 'a1' }, { b: 'b1' }));