-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from testing-library/next
chore(release): promote v5 as an main consumption release
- Loading branch information
Showing
35 changed files
with
457 additions
and
360 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
scripts/* | ||
.eslintignore | ||
.prettierignore | ||
.all-contributorsrc |
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
This file was deleted.
Oops, something went wrong.
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
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,35 @@ | ||
import { cleanup, render } from '@testing-library/svelte' | ||
import { describe, expect, test, vi } from 'vitest' | ||
|
||
import Mounter from './fixtures/Mounter.svelte' | ||
|
||
const onExecuted = vi.fn() | ||
const onDestroyed = vi.fn() | ||
const renderSubject = () => render(Mounter, { onExecuted, onDestroyed }) | ||
|
||
describe('cleanup', () => { | ||
test('cleanup deletes element', async () => { | ||
renderSubject() | ||
cleanup() | ||
|
||
expect(document.body).toBeEmptyDOMElement() | ||
}) | ||
|
||
test('cleanup unmounts component', () => { | ||
renderSubject() | ||
cleanup() | ||
|
||
expect(onDestroyed).toHaveBeenCalledOnce() | ||
}) | ||
|
||
test('cleanup handles unexpected errors during mount', () => { | ||
onExecuted.mockImplementation(() => { | ||
throw new Error('oh no!') | ||
}) | ||
|
||
expect(renderSubject).toThrowError() | ||
cleanup() | ||
|
||
expect(document.body).toBeEmptyDOMElement() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import { prettyDOM } from '@testing-library/dom' | ||
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest' | ||
import { render } from '@testing-library/svelte' | ||
import { describe, expect, test, vi } from 'vitest' | ||
|
||
import { render } from '..' | ||
import Comp from './fixtures/Comp.svelte' | ||
|
||
describe('debug', () => { | ||
beforeEach(() => { | ||
vi.spyOn(console, 'log').mockImplementation(() => { }) | ||
}) | ||
|
||
afterEach(() => { | ||
console.log.mockRestore() | ||
}) | ||
test('pretty prints the base element', () => { | ||
vi.stubGlobal('console', { log: vi.fn(), warn: vi.fn(), error: vi.fn() }) | ||
|
||
test('pretty prints the container', () => { | ||
const { container, debug } = render(Comp, { props: { name: 'world' } }) | ||
const { baseElement, debug } = render(Comp, { props: { name: 'world' } }) | ||
|
||
debug() | ||
|
||
expect(console.log).toHaveBeenCalledTimes(1) | ||
expect(console.log).toHaveBeenCalledWith(prettyDOM(container)) | ||
expect(console.log).toHaveBeenCalledWith(prettyDOM(baseElement)) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,30 +1,32 @@ | ||
import { fireEvent, render } from '@testing-library/svelte' | ||
import { describe, expect, test } from 'vitest' | ||
|
||
import { fireEvent, render } from '..' | ||
import Comp from './fixtures/Comp.svelte' | ||
|
||
describe('events', () => { | ||
test('state changes are flushed after firing an event', async () => { | ||
const { getByText } = render(Comp, { props: { name: 'World' } }) | ||
const button = getByText('Button') | ||
|
||
await fireEvent.click(button) | ||
const result = fireEvent.click(button) | ||
|
||
await expect(result).resolves.toBe(true) | ||
expect(button).toHaveTextContent('Button Clicked') | ||
}) | ||
|
||
test('calling `fireEvent` directly works too', async () => { | ||
const { getByText } = render(Comp, { props: { name: 'World' } }) | ||
const button = getByText('Button') | ||
|
||
await fireEvent( | ||
const result = fireEvent( | ||
button, | ||
new MouseEvent('click', { | ||
bubbles: true, | ||
cancelable: true | ||
cancelable: true, | ||
}) | ||
) | ||
|
||
await expect(result).resolves.toBe(true) | ||
expect(button).toHaveTextContent('Button Clicked') | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,23 +1,17 @@ | ||
<svelte:options accessors /> | ||
|
||
<script> | ||
import { getContext } from 'svelte' | ||
export let name | ||
export let name = 'World' | ||
let buttonText = 'Button' | ||
const contextName = getContext('name') | ||
function handleClick () { | ||
function handleClick() { | ||
buttonText = 'Button Clicked' | ||
} | ||
</script> | ||
|
||
<h1 data-testid="test">Hello {name}!</h1> | ||
|
||
<div>we have {contextName}</div> | ||
|
||
<button on:click={handleClick}>{buttonText}</button> | ||
|
||
<style></style> |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<script> | ||
import { getContext } from 'svelte'; | ||
import { getContext } from 'svelte' | ||
const ctx = getContext('foo'); | ||
const ctx = getContext('foo') | ||
</script> | ||
|
||
<div>{ctx.message}</div> |
Oops, something went wrong.