docs icon indicating copy to clipboard operation
docs copied to clipboard

Explain how `.provide()` can not be called imperatively to override implementations

Open kevinmaes opened this issue 2 years ago • 3 comments

kevinmaes avatar Jun 12 '23 22:06 kevinmaes

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Jul 11, 2023 9:26am

vercel[bot] avatar Jun 12 '23 22:06 vercel[bot]

Does the new setup() api make this PR obsolete? @Andarist @davidkpiano

kevinmaes avatar Nov 29 '23 12:11 kevinmaes

Not exactly. With setup you have to "provide" all implementations upfront - so you should never end up with missing implementations but you can still override/mock them afterward. This works just fine today:

setup({
  actors: {
    fetchUser: fromPromise(() => fetch("/user")),
  },
})
  .createMachine({})
  .provide({
    actors: {
      fetchUser: fromPromise(() => Promise.resolve({ name: "Kevin" })),
    },
  });

Andarist avatar Nov 29 '23 13:11 Andarist