-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
spawn
input required when defined (with tests)
- Loading branch information
1 parent
88d7fca
commit 7dc0b12
Showing
4 changed files
with
133 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ActorRefFrom, createActor, createMachine } from '../src'; | ||
|
||
describe('spawn inside machine', () => { | ||
it('input is required when defined in actor', () => { | ||
const childMachine = createMachine({ | ||
types: { input: {} as { value: number } } | ||
}); | ||
const machine = createMachine({ | ||
types: {} as { context: { ref: ActorRefFrom<typeof childMachine> } }, | ||
context: ({ spawn }) => ({ | ||
ref: spawn(childMachine, { input: { value: 42 }, systemId: 'test' }) | ||
}) | ||
}); | ||
|
||
const actor = createActor(machine).start(); | ||
expect(actor.system.get('test')).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ActorRefFrom, assign, createMachine } from '../src'; | ||
|
||
describe('spawn inside machine', () => { | ||
it('input is required when defined in actor', () => { | ||
const childMachine = createMachine({ | ||
types: { input: {} as { value: number } } | ||
}); | ||
createMachine({ | ||
types: {} as { context: { ref: ActorRefFrom<typeof childMachine> } }, | ||
context: ({ spawn }) => ({ | ||
ref: spawn(childMachine, { input: { value: 42 } }) | ||
}), | ||
initial: 'idle', | ||
states: { | ||
Idle: { | ||
on: { | ||
event: { | ||
actions: assign(({ spawn }) => ({ | ||
ref: spawn(childMachine, { input: { value: 42 } }) | ||
})) | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
it('input is not required when not defined in actor', () => { | ||
const childMachine = createMachine({}); | ||
createMachine({ | ||
types: {} as { context: { ref: ActorRefFrom<typeof childMachine> } }, | ||
context: ({ spawn }) => ({ | ||
ref: spawn(childMachine) | ||
}), | ||
initial: 'idle', | ||
states: { | ||
Idle: { | ||
on: { | ||
some: { | ||
actions: assign(({ spawn }) => ({ | ||
ref: spawn(childMachine) | ||
})) | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
}); |