Skip to content

Commit

Permalink
Ensuring matchesState returns false when parent is more specific than…
Browse files Browse the repository at this point in the history
… child. Fixes #69
  • Loading branch information
davidkpiano committed Apr 23, 2018
1 parent 5bcee08 commit 3cd7bd6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/graph.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StateNode } from './index';
import { toStateValue } from './utils';
import { toStateValue, getActionType } from './utils';
import {
StateValue,
Machine,
Expand Down Expand Up @@ -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
};
});
Expand Down
3 changes: 2 additions & 1 deletion src/matchesState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
11 changes: 5 additions & 6 deletions test/matchesState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }));
Expand Down

0 comments on commit 3cd7bd6

Please sign in to comment.