testing-library/svelte-testing-library

How to properly test context API

halafi opened this issue · 2 comments

I haven't found much in docs, how can I pass context what normally would be done by a parent component?

if I do something like:

setContext('foo', {
    bar: { kek: 'bur' },
  });
 render(...);

I get an error: Function called outside component initialisation

and I haven't noticed a way to pass the context to render function call.

Is there any better way than creating a redundant component parent?

This might work

render(MyComponent, {
      context: new Map(Object.entries({ foo: { bar: { kek:'bur' } } }))
 })

@danielfyhr got it. I'm adding a test to the repo so that we keep that in mind somewhere.