diff --git a/.all-contributorsrc b/.all-contributorsrc
index 1f04b01..04f7270 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -2,9 +2,7 @@
"projectName": "svelte-testing-library",
"projectOwner": "testing-library",
"repoType": "github",
- "files": [
- "README.md"
- ],
+ "files": ["README.md"],
"imageSize": 100,
"commit": false,
"contributors": [
@@ -13,133 +11,91 @@
"name": "Ben Monro",
"avatar_url": "https://avatars3.githubusercontent.com/u/399236?v=4",
"profile": "https://github.com/benmonro",
- "contributions": [
- "code",
- "test",
- "ideas",
- "doc"
- ]
+ "contributions": ["code", "test", "ideas", "doc"]
},
{
"login": "EmilTholin",
"name": "Emil Tholin",
"avatar_url": "https://avatars0.githubusercontent.com/u/11573167?v=4",
"profile": "https://twitter.com/EmilTholin",
- "contributions": [
- "code",
- "test",
- "ideas"
- ]
+ "contributions": ["code", "test", "ideas"]
},
{
"login": "oieduardorabelo",
"name": "Eduardo Rabelo",
"avatar_url": "https://avatars1.githubusercontent.com/u/829902?v=4",
"profile": "https://medium.com/@oieduardorabelo",
- "contributions": [
- "test",
- "code",
- "doc",
- "example"
- ]
+ "contributions": ["test", "code", "doc", "example"]
},
{
"login": "timdeschryver",
"name": "Tim Deschryver",
"avatar_url": "https://avatars1.githubusercontent.com/u/28659384?v=4",
"profile": "http://timdeschryver.dev",
- "contributions": [
- "doc"
- ]
+ "contributions": ["doc"]
},
{
"login": "ematipico",
"name": "Emanuele",
"avatar_url": "https://avatars3.githubusercontent.com/u/602478?v=4",
"profile": "http://www.ematipico.com",
- "contributions": [
- "code",
- "test",
- "doc"
- ]
+ "contributions": ["code", "test", "doc"]
},
{
"login": "pngwn",
"name": "pngwn",
"avatar_url": "https://avatars1.githubusercontent.com/u/12937446?v=4",
"profile": "https://github.com/pngwn",
- "contributions": [
- "code",
- "test"
- ]
+ "contributions": ["code", "test"]
},
{
"login": "eps1lon",
"name": "Sebastian Silbermann",
"avatar_url": "https://avatars3.githubusercontent.com/u/12292047?v=4",
"profile": "https://twitter.com/sebsilbermann",
- "contributions": [
- "code"
- ]
+ "contributions": ["code"]
},
{
"login": "mihar-22",
"name": "Rahim Alwer",
"avatar_url": "https://avatars3.githubusercontent.com/u/14304599?s=460&v=4",
"profile": "https://github.com/mihar-22",
- "contributions": [
- "code",
- "doc",
- "test",
- "review"
- ]
+ "contributions": ["code", "doc", "test", "review"]
},
{
"login": "MirrorBytes",
"name": "Bob",
"avatar_url": "https://avatars3.githubusercontent.com/u/22119469?v=4",
"profile": "https://github.com/MirrorBytes",
- "contributions": [
- "bug",
- "code"
- ]
+ "contributions": ["bug", "code"]
},
{
"login": "ronmerkin",
"name": "Ron Merkin",
"avatar_url": "https://avatars.githubusercontent.com/u/17492527?v=4",
"profile": "https://github.com/ronmerkin",
- "contributions": [
- "code"
- ]
+ "contributions": ["code"]
},
{
"login": "benmccann",
"name": "Ben McCann",
"avatar_url": "https://avatars.githubusercontent.com/u/322311?v=4",
"profile": "http://www.benmccann.com",
- "contributions": [
- "test"
- ]
+ "contributions": ["test"]
},
{
"login": "jgbowser",
"name": "John Bowser",
"avatar_url": "https://avatars.githubusercontent.com/u/66637570?v=4",
"profile": "https://johnbowser.dev/",
- "contributions": [
- "code",
- "test"
- ]
+ "contributions": ["code", "test"]
},
{
"login": "ysitbon",
"name": "Yoann",
"avatar_url": "https://avatars.githubusercontent.com/u/1370679?v=4",
"profile": "https://github.com/ysitbon",
- "contributions": [
- "code"
- ]
+ "contributions": ["code"]
}
],
"contributorsPerLine": 7,
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 4851fc4..44d09ef 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -1,25 +1,25 @@
version: 2
updates:
-- package-ecosystem: npm
- directory: "/"
- schedule:
- interval: daily
- time: "10:00"
- open-pull-requests-limit: 10
- ignore:
- - dependency-name: husky
- versions:
- - 5.0.9
- - 5.1.0
- - 5.1.1
- - 5.1.2
- - 5.1.3
- - 5.2.0
- - dependency-name: "@commitlint/config-conventional"
- versions:
- - 12.0.0
- - 12.0.1
- - dependency-name: "@commitlint/cli"
- versions:
- - 12.0.0
- - 12.0.1
+ - package-ecosystem: npm
+ directory: '/'
+ schedule:
+ interval: daily
+ time: '10:00'
+ open-pull-requests-limit: 10
+ ignore:
+ - dependency-name: husky
+ versions:
+ - 5.0.9
+ - 5.1.0
+ - 5.1.1
+ - 5.1.2
+ - 5.1.3
+ - 5.2.0
+ - dependency-name: '@commitlint/config-conventional'
+ versions:
+ - 12.0.0
+ - 12.0.1
+ - dependency-name: '@commitlint/cli'
+ versions:
+ - 12.0.0
+ - 12.0.1
diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml
index ad6df65..376bf57 100644
--- a/.github/workflows/lint-pr.yml
+++ b/.github/workflows/lint-pr.yml
@@ -1,4 +1,4 @@
-name: "Lint PR"
+name: 'Lint PR'
on:
pull_request_target:
diff --git a/.prettierrc.yaml b/.prettierrc.yaml
index e1bf864..0a2ace3 100644
--- a/.prettierrc.yaml
+++ b/.prettierrc.yaml
@@ -4,6 +4,6 @@ trailingComma: es5
plugins:
- prettier-plugin-svelte
overrides:
- - files: "*.svelte"
+ - files: '*.svelte'
options:
parser: svelte
diff --git a/README.md b/README.md
index 0808979..48bf5ce 100644
--- a/README.md
+++ b/README.md
@@ -38,7 +38,6 @@
-
- [The Problem](#the-problem)
- [This Solution](#this-solution)
- [Installation](#installation)
@@ -119,23 +118,25 @@ Thanks goes to these people ([emoji key][emojis]):
@@ -187,4 +188,3 @@ Contributions of any kind welcome!
[stackoverflow]: https://stackoverflow.com/questions/tagged/svelte-testing-library
-
diff --git a/package.json b/package.json
index afe5e54..91d7e66 100644
--- a/package.json
+++ b/package.json
@@ -44,7 +44,7 @@
],
"scripts": {
"toc": "doctoc README.md",
- "lint": "(prettier . --check || true) && eslint .",
+ "lint": "prettier . --check && eslint .",
"format": "prettier . --write && eslint . --fix",
"test": "vitest run --coverage",
"test:watch": "vitest",
diff --git a/src/__tests__/act.test.js b/src/__tests__/act.test.js
index 6eafc0d..224d904 100644
--- a/src/__tests__/act.test.js
+++ b/src/__tests__/act.test.js
@@ -8,13 +8,13 @@ describe('act', () => {
const render = () => {
return stlRender(Comp, {
- props
+ props,
})
}
beforeEach(() => {
props = {
- name: 'World'
+ name: 'World',
}
})
diff --git a/src/__tests__/debug.test.js b/src/__tests__/debug.test.js
index 1072a0f..816c357 100644
--- a/src/__tests__/debug.test.js
+++ b/src/__tests__/debug.test.js
@@ -6,7 +6,7 @@ import Comp from './fixtures/Comp.svelte'
describe('debug', () => {
beforeEach(() => {
- vi.spyOn(console, 'log').mockImplementation(() => { })
+ vi.spyOn(console, 'log').mockImplementation(() => {})
})
afterEach(() => {
diff --git a/src/__tests__/events.test.js b/src/__tests__/events.test.js
index fccf990..1656a8b 100644
--- a/src/__tests__/events.test.js
+++ b/src/__tests__/events.test.js
@@ -21,7 +21,7 @@ describe('events', () => {
button,
new MouseEvent('click', {
bubbles: true,
- cancelable: true
+ cancelable: true,
})
)
diff --git a/src/__tests__/fixtures/Comp.svelte b/src/__tests__/fixtures/Comp.svelte
index ec04c05..e8abe27 100644
--- a/src/__tests__/fixtures/Comp.svelte
+++ b/src/__tests__/fixtures/Comp.svelte
@@ -9,7 +9,7 @@
const contextName = getContext('name')
- function handleClick () {
+ function handleClick() {
buttonText = 'Button Clicked'
}
diff --git a/src/__tests__/fixtures/Comp2.svelte b/src/__tests__/fixtures/Comp2.svelte
index 104e81a..33e36c7 100644
--- a/src/__tests__/fixtures/Comp2.svelte
+++ b/src/__tests__/fixtures/Comp2.svelte
@@ -3,13 +3,13 @@
let buttonText = 'Button Text'
- function handleClick () {
+ function handleClick() {
buttonText = 'Button Clicked'
}
-
-
Hello {name}!
+
+
diff --git a/src/__tests__/fixtures/Context.svelte b/src/__tests__/fixtures/Context.svelte
index be8253b..d6515d5 100644
--- a/src/__tests__/fixtures/Context.svelte
+++ b/src/__tests__/fixtures/Context.svelte
@@ -1,7 +1,7 @@
{ctx.message}
diff --git a/src/__tests__/fixtures/Stopwatch.svelte b/src/__tests__/fixtures/Stopwatch.svelte
index 2c275e5..1fd5e64 100644
--- a/src/__tests__/fixtures/Stopwatch.svelte
+++ b/src/__tests__/fixtures/Stopwatch.svelte
@@ -5,7 +5,7 @@
let lapse = 0
let running = false
- function handleRunClick () {
+ function handleRunClick() {
if (running) {
clearInterval(timer)
} else {
@@ -18,7 +18,7 @@
running = true
}
- function handleClearClick () {
+ function handleClearClick() {
clearInterval(timer)
lapse = 0
running = false
@@ -29,8 +29,6 @@
})
-
-
{lapse}ms
+
+
diff --git a/src/__tests__/multi-base.test.js b/src/__tests__/multi-base.test.js
index 39f28d1..5b6b474 100644
--- a/src/__tests__/multi-base.test.js
+++ b/src/__tests__/multi-base.test.js
@@ -13,11 +13,11 @@ describe('multi-base', () => {
{
target: treeA,
props: {
- name: 'Tree A'
- }
+ name: 'Tree A',
+ },
},
{
- container: treeA
+ container: treeA,
}
)
@@ -26,11 +26,11 @@ describe('multi-base', () => {
{
target: treeB,
props: {
- name: 'Tree B'
- }
+ name: 'Tree B',
+ },
},
{
- container: treeB
+ container: treeB,
}
)
diff --git a/src/__tests__/render.test.js b/src/__tests__/render.test.js
index 6beb984..8d5c3cf 100644
--- a/src/__tests__/render.test.js
+++ b/src/__tests__/render.test.js
@@ -11,13 +11,13 @@ describe('render', () => {
return stlRender(Comp, {
target: document.body,
props,
- ...additional
+ ...additional,
})
}
beforeEach(() => {
props = {
- name: 'World'
+ name: 'World',
}
})
@@ -68,7 +68,7 @@ describe('render', () => {
target,
anchor: div,
props: { name: 'World' },
- context: new Map([['name', 'context']])
+ context: new Map([['name', 'context']]),
})
expect(container).toMatchSnapshot()
})
@@ -94,9 +94,9 @@ describe('render', () => {
test("accept the 'context' option", () => {
const { getByText } = stlRender(Comp, {
props: {
- name: 'Universe'
+ name: 'Universe',
},
- context: new Map([['name', 'context']])
+ context: new Map([['name', 'context']]),
})
expect(getByText('we have context')).toBeInTheDocument()
diff --git a/src/pure.js b/src/pure.js
index 6d49434..2610db6 100644
--- a/src/pure.js
+++ b/src/pure.js
@@ -1,7 +1,7 @@
import {
fireEvent as dtlFireEvent,
getQueriesForElement,
- prettyDOM
+ prettyDOM,
} from '@testing-library/dom'
import { tick } from 'svelte'
@@ -14,7 +14,7 @@ const svelteComponentOptions = [
'props',
'hydrate',
'intro',
- 'context'
+ 'context',
]
const render = (
@@ -56,7 +56,7 @@ const render = (
let component = new ComponentConstructor({
target,
- ...checkProps(options)
+ ...checkProps(options),
})
containerCache.add({ container, target, component })
@@ -76,7 +76,7 @@ const render = (
// eslint-disable-next-line no-new
component = new ComponentConstructor({
target,
- ...checkProps(options)
+ ...checkProps(options),
})
containerCache.add({ container, target, component })
@@ -89,7 +89,7 @@ const render = (
unmount: () => {
if (componentCache.has(component)) component.$destroy()
},
- ...getQueriesForElement(container, queries)
+ ...getQueriesForElement(container, queries),
}
}
diff --git a/svelte.config.js b/svelte.config.js
index 61eb947..b0683fd 100644
--- a/svelte.config.js
+++ b/svelte.config.js
@@ -1,7 +1,7 @@
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
export default {
- // Consult https://svelte.dev/docs#compile-time-svelte-preprocess
- // for more information about preprocessors
- preprocess: vitePreprocess(),
+ // Consult https://svelte.dev/docs#compile-time-svelte-preprocess
+ // for more information about preprocessors
+ preprocess: vitePreprocess(),
}
diff --git a/types/index.d.ts b/types/index.d.ts
index 26d85d7..dc334d9 100644
--- a/types/index.d.ts
+++ b/types/index.d.ts
@@ -2,21 +2,38 @@
// Project: https://github.com/testing-library/svelte-testing-library
// Definitions by: Rahim Alwer
-import {BoundFunction, EventType,Queries, queries} from '@testing-library/dom'
-import { ComponentConstructorOptions,ComponentProps, SvelteComponent } from 'svelte'
+import {
+ BoundFunction,
+ EventType,
+ Queries,
+ queries,
+} from '@testing-library/dom'
+import {
+ ComponentConstructorOptions,
+ ComponentProps,
+ SvelteComponent,
+} from 'svelte'
export * from '@testing-library/dom'
-type SvelteComponentOptions = ComponentProps | Pick>, "anchor" | "props" | "hydrate" | "intro" | "context">
+type SvelteComponentOptions =
+ | ComponentProps
+ | Pick<
+ ComponentConstructorOptions>,
+ 'anchor' | 'props' | 'hydrate' | 'intro' | 'context'
+ >
type Omit = Pick>
-type Constructor = new (...args: any[]) => T;
+type Constructor = new (...args: any[]) => T
/**
* Render a Component into the Document.
*/
-export type RenderResult = {
+export type RenderResult<
+ C extends SvelteComponent,
+ Q extends Queries = typeof queries,
+> = {
container: HTMLElement
component: C
debug: (el?: HTMLElement | DocumentFragment) => void
@@ -38,7 +55,7 @@ export function render(
export function render(
component: Constructor,
componentOptions?: SvelteComponentOptions,
- renderOptions?: RenderOptions,
+ renderOptions?: RenderOptions
): RenderResult
/**
@@ -50,13 +67,19 @@ export function cleanup(): void
* Fires DOM events on an element provided by @testing-library/dom. Since Svelte needs to flush
* pending state changes via `tick`, these methods have been override and now return a promise.
*/
-export type FireFunction = (element: Document | Element | Window, event: Event) => Promise;
+export type FireFunction = (
+ element: Document | Element | Window,
+ event: Event
+) => Promise
export type FireObject = {
- [K in EventType]: (element: Document | Element | Window, options?: {}) => Promise;
-};
+ [K in EventType]: (
+ element: Document | Element | Window,
+ options?: {}
+ ) => Promise
+}
-export const fireEvent: FireFunction & FireObject;
+export const fireEvent: FireFunction & FireObject
/**
* Calls a function and notifies Svelte to flush any pending state changes.