Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test case related to invokes and history states #4370

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion packages/core/test/history.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createActor, createMachine } from '../src/index';
import { createActor, createMachine, fromCallback } from '../src/index';

describe('history states', () => {
it('should go to the most recently visited state (explicit shallow history type)', () => {
Expand Down Expand Up @@ -499,6 +499,35 @@ describe('history states', () => {

expect(spy).toHaveBeenCalledTimes(1);
});

it('should invoke an actor when reentering the stored configuration through the history state', () => {
const spy = jest.fn();

const machine = createMachine({
initial: 'running',
states: {
running: {
on: {
PING: {
target: 'refresh'
}
},
invoke: {
src: fromCallback(spy)
}
},
refresh: {
type: 'history'
}
}
});
const actorRef = createActor(machine).start();
spy.mockClear();

actorRef.send({ type: 'PING' });

expect(spy).toHaveBeenCalledTimes(1);
});
});

describe('deep history states', () => {
Expand Down