Skip to content

Commit 16f6b40

Browse files
authored
test: remove unnecessary tests and skips (#338)
1 parent 8d98aa5 commit 16f6b40

17 files changed

+54
-85
lines changed

.eslintrc.cjs

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ module.exports = {
2323
parserOptions: {
2424
parser: '@typescript-eslint/parser',
2525
},
26+
rules: {
27+
'no-undef-init': 'off',
28+
},
2629
},
2730
{
2831
files: ['*.ts'],

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
scripts/*
22
.eslintignore
33
.prettierignore
4+
.all-contributorsrc

.prettierrc.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ trailingComma: es5
44
plugins:
55
- prettier-plugin-svelte
66
overrides:
7-
- files: "*.svelte"
7+
- files: '*.svelte'
88
options:
99
parser: svelte

src/__tests__/act.test.js

+8-31
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
import { beforeEach, describe, expect, test } from 'vitest'
1+
import { setTimeout } from 'node:timers/promises'
2+
3+
import { act, render } from '@testing-library/svelte'
4+
import { describe, expect, test } from 'vitest'
25

3-
import { act, fireEvent, render as stlRender } from '@testing-library/svelte'
46
import Comp from './fixtures/Comp.svelte'
57

68
describe('act', () => {
7-
let props
8-
9-
const render = () => {
10-
return stlRender(Comp, {
11-
props
12-
})
13-
}
14-
15-
beforeEach(() => {
16-
props = {
17-
name: 'World'
18-
}
19-
})
20-
219
test('state updates are flushed', async () => {
22-
const { getByText } = render()
10+
const { getByText } = render(Comp)
2311
const button = getByText('Button')
2412

2513
expect(button).toHaveTextContent('Button')
@@ -31,24 +19,13 @@ describe('act', () => {
3119
expect(button).toHaveTextContent('Button Clicked')
3220
})
3321

34-
test('findByTestId returns the element', async () => {
35-
const { findByTestId } = render()
36-
37-
expect(await findByTestId('test')).toHaveTextContent(`Hello ${props.name}!`)
38-
})
39-
4022
test('accepts async functions', async () => {
41-
const sleep = (ms) =>
42-
new Promise((resolve) => {
43-
setTimeout(() => resolve(), ms)
44-
})
45-
46-
const { getByText } = render()
23+
const { getByText } = render(Comp)
4724
const button = getByText('Button')
4825

4926
await act(async () => {
50-
await sleep(100)
51-
await fireEvent.click(button)
27+
await setTimeout(100)
28+
button.click()
5229
})
5330

5431
expect(button).toHaveTextContent('Button Clicked')

src/__tests__/auto-cleanup.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { render } from '@testing-library/svelte'
12
import { describe, expect, test } from 'vitest'
23

3-
import { render } from '@testing-library/svelte'
44
import Comp from './fixtures/Comp.svelte'
55

66
describe('auto-cleanup', () => {

src/__tests__/cleanup.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import { cleanup, render } from '@testing-library/svelte'
12
import { describe, expect, test, vi } from 'vitest'
2-
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
33

4-
import { act, cleanup, render } from '@testing-library/svelte'
54
import Mounter from './fixtures/Mounter.svelte'
65

76
const onExecuted = vi.fn()
@@ -16,8 +15,8 @@ describe('cleanup', () => {
1615
expect(document.body).toBeEmptyDOMElement()
1716
})
1817

19-
test.runIf(SVELTE_VERSION < '5')('cleanup unmounts component', async () => {
20-
await act(renderSubject)
18+
test('cleanup unmounts component', () => {
19+
renderSubject()
2120
cleanup()
2221

2322
expect(onDestroyed).toHaveBeenCalledOnce()

src/__tests__/context.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { render } from '@testing-library/svelte'
12
import { expect, test } from 'vitest'
23

3-
import { render } from '@testing-library/svelte'
44
import Comp from './fixtures/Context.svelte'
55
import { IS_HAPPYDOM, IS_SVELTE_5 } from './utils.js'
66

src/__tests__/debug.test.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import { prettyDOM } from '@testing-library/dom'
2-
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
3-
42
import { render } from '@testing-library/svelte'
3+
import { describe, expect, test, vi } from 'vitest'
4+
55
import Comp from './fixtures/Comp.svelte'
66

77
describe('debug', () => {
8-
beforeEach(() => {
9-
vi.spyOn(console, 'log').mockImplementation(() => {})
10-
})
11-
12-
afterEach(() => {
13-
console.log.mockRestore()
14-
})
15-
168
test('pretty prints the base element', () => {
9+
vi.stubGlobal('console', { log: vi.fn(), warn: vi.fn(), error: vi.fn() })
10+
1711
const { baseElement, debug } = render(Comp, { props: { name: 'world' } })
1812

1913
debug()

src/__tests__/events.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { fireEvent, render } from '@testing-library/svelte'
12
import { describe, expect, test } from 'vitest'
23

3-
import { fireEvent, render } from '@testing-library/svelte'
44
import Comp from './fixtures/Comp.svelte'
55

66
describe('events', () => {
@@ -21,7 +21,7 @@ describe('events', () => {
2121
button,
2222
new MouseEvent('click', {
2323
bubbles: true,
24-
cancelable: true
24+
cancelable: true,
2525
})
2626
)
2727

src/__tests__/fixtures/Comp.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<svelte:options accessors />
22

33
<script>
4-
export let name
4+
export let name = 'World'
55
66
let buttonText = 'Button'
77

src/__tests__/fixtures/Context.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
2-
import { getContext } from 'svelte';
2+
import { getContext } from 'svelte'
33
4-
const ctx = getContext('foo');
4+
const ctx = getContext('foo')
55
</script>
66

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

src/__tests__/mount.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { act, render, screen } from '@testing-library/svelte'
12
import { describe, expect, test, vi } from 'vitest'
23

3-
import { act, render, screen } from '@testing-library/svelte'
44
import Mounter from './fixtures/Mounter.svelte'
55
import { IS_HAPPYDOM, IS_SVELTE_5 } from './utils.js'
66

src/__tests__/render.test.js

+18-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { render } from '@testing-library/svelte'
2-
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'
32
import { describe, expect, test } from 'vitest'
43

54
import Comp from './fixtures/Comp.svelte'
5+
import { IS_SVELTE_5 } from './utils.js'
66

77
describe('render', () => {
88
const props = { name: 'World' }
@@ -65,24 +65,21 @@ describe('render', () => {
6565
expect(baseElement.firstChild).toBe(container)
6666
})
6767

68-
test.runIf(SVELTE_VERSION < '5')(
69-
'should accept anchor option in Svelte v4',
70-
() => {
71-
const baseElement = document.body
72-
const target = document.createElement('section')
73-
const anchor = document.createElement('div')
74-
baseElement.appendChild(target)
75-
target.appendChild(anchor)
76-
77-
const { getByTestId } = render(
78-
Comp,
79-
{ props, target, anchor },
80-
{ baseElement }
81-
)
82-
const firstElement = getByTestId('test')
83-
84-
expect(target.firstChild).toBe(firstElement)
85-
expect(target.lastChild).toBe(anchor)
86-
}
87-
)
68+
test.skipIf(IS_SVELTE_5)('should accept anchor option in Svelte v4', () => {
69+
const baseElement = document.body
70+
const target = document.createElement('section')
71+
const anchor = document.createElement('div')
72+
baseElement.appendChild(target)
73+
target.appendChild(anchor)
74+
75+
const { getByTestId } = render(
76+
Comp,
77+
{ props, target, anchor },
78+
{ baseElement }
79+
)
80+
const firstElement = getByTestId('test')
81+
82+
expect(target.firstChild).toBe(firstElement)
83+
expect(target.lastChild).toBe(anchor)
84+
})
8885
})

src/__tests__/rerender.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('rerender', () => {
1515
})
1616

1717
test('warns if incorrect arguments shape used', async () => {
18-
vi.stubGlobal('console', { warn: vi.fn() })
18+
vi.stubGlobal('console', { log: vi.fn(), warn: vi.fn(), error: vi.fn() })
1919

2020
const { rerender } = render(Comp, { name: 'World' })
2121
const element = screen.getByText('Hello World!')

src/__tests__/transition.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import { render, screen, waitFor } from '@testing-library/svelte'
12
import { userEvent } from '@testing-library/user-event'
23
import { beforeEach, describe, expect, test, vi } from 'vitest'
34

4-
import { IS_JSDOM, IS_SVELTE_5 } from './utils.js'
5-
6-
import { render, screen, waitFor } from '@testing-library/svelte'
75
import Transitioner from './fixtures/Transitioner.svelte'
6+
import { IS_JSDOM, IS_SVELTE_5 } from './utils.js'
87

9-
describe.runIf(!IS_SVELTE_5)('transitions', () => {
8+
describe.skipIf(IS_SVELTE_5)('transitions', () => {
109
beforeEach(() => {
1110
if (!IS_JSDOM) return
1211

src/vitest.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { afterEach } from 'vitest'
2-
31
import { act, cleanup } from '@testing-library/svelte'
2+
import { afterEach } from 'vitest'
43

54
afterEach(async () => {
65
await act()

svelte.config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
22

33
export default {
4-
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
5-
// for more information about preprocessors
6-
preprocess: vitePreprocess(),
4+
// Consult https://svelte.dev/docs#compile-time-svelte-preprocess
5+
// for more information about preprocessors
6+
preprocess: vitePreprocess(),
77
}

0 commit comments

Comments
 (0)