Skip to content

Commit

Permalink
machine.resolveState(state) calls should resolve to the correct val…
Browse files Browse the repository at this point in the history
…ue of `.done` property now (#1816)
  • Loading branch information
Andarist committed Jan 6, 2021
1 parent 07980da commit 0cb8df9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-pets-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': patch
---

`machine.resolveState(state)` calls should resolve to the correct value of `.done` property now.
3 changes: 2 additions & 1 deletion packages/core/src/StateNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,8 @@ class StateNode<
return new State({
...state,
value: this.resolve(state.value),
configuration
configuration,
done: isInFinalState(configuration, this)
});
}

Expand Down
21 changes: 20 additions & 1 deletion packages/core/test/machine.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Machine, interpret } from '../src/index';
import { Machine, interpret, createMachine } from '../src/index';
import { State } from '../src/State';

const pedestrianStates = {
Expand Down Expand Up @@ -282,6 +282,25 @@ describe('machine', () => {

expect(resolvedState.nextEvents.sort()).toEqual(['TO_BAR', 'TO_TWO']);
});

it('should resolve .done', () => {
const machine = createMachine({
initial: 'foo',
states: {
foo: {
on: { NEXT: 'bar' }
},
bar: {
type: 'final'
}
}
});
const tempState = State.from<any>('bar');

const resolvedState = machine.resolveState(tempState);

expect(resolvedState.done).toBe(true);
});
});

describe('versioning', () => {
Expand Down

0 comments on commit 0cb8df9

Please sign in to comment.