Skip to content

Commit

Permalink
Merge pull request #287 from testing-library/gh209-setContext
Browse files Browse the repository at this point in the history
chore: add new context test
  • Loading branch information
yanick authored Jan 25, 2024
2 parents 9fdce65 + 614b9b7 commit 9bd2f39
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/__tests__/context.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { expect, test } from 'vitest'

import { render } from '..'
import Comp from './fixtures/Context.svelte'

test('can set a context', () => {
const message = 'Got it'

const { getByText } = render(Comp, {
context: new Map(Object.entries({ foo: { message } })),
})

expect(getByText(message)).toBeTruthy()
})
7 changes: 7 additions & 0 deletions src/__tests__/fixtures/Context.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import { getContext } from 'svelte';
const ctx = getContext('foo');
</script>

<div>{ctx.message}</div>

0 comments on commit 9bd2f39

Please sign in to comment.