Skip to content

Commit 27921ba

Browse files
committed
fix(test): destroy Tiptap editor everywhere at the end of the tests
Signed-off-by: Jonas <jonas@freesources.org>
1 parent 50fbbb1 commit 27921ba

12 files changed

Lines changed: 42 additions & 8 deletions

File tree

src/tests/components/Editor/TableOfContents.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ test('renders nothing for editor without headings', () => {
3030
const wrapper = mountWithEditor(editor)
3131
expect(wrapper.text()).toEqual('')
3232
expect(wrapper.vm.$data.headings).toEqual([])
33+
editor.destroy()
3334
})
3435

3536
test('renders initial heading', async () => {
@@ -38,6 +39,7 @@ test('renders initial heading', async () => {
3839
await nextTick()
3940
expect(wrapper.text()).toEqual(text)
4041
expect(wrapper.vm.$data.headings).toEqual(headingsForContent)
42+
editor.destroy()
4143
})
4244

4345
test('updates according to editor changes', async () => {
@@ -48,6 +50,7 @@ test('updates according to editor changes', async () => {
4850
await nextTick()
4951
expect(wrapper.text()).toEqual(text)
5052
expect(wrapper.vm.$data.headings).toEqual(headingsForContent)
53+
editor.destroy()
5154
})
5255

5356
test('disconnects on destroy', async () => {
@@ -58,4 +61,5 @@ test('disconnects on destroy', async () => {
5861
expect(on).toHaveBeenCalledWith('update', expect.any(Function))
5962
wrapper.destroy()
6063
expect(off).toHaveBeenCalledWith('update', expect.any(Function))
64+
editor.destroy()
6165
})

src/tests/components/Menu/TranslateButton.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ test('does not render without state', async () => {
3636
const wrapper = mountWithEditor(editor)
3737
await nextTick()
3838
expect(wrapper.find('button').exists()).toBe(false)
39+
editor.destroy()
3940
})
4041

4142
test('does render with translations', async () => {
@@ -44,6 +45,7 @@ test('does render with translations', async () => {
4445
const wrapper = mountWithEditor(editor)
4546
await nextTick()
4647
expect(wrapper.find('button').exists()).toBe(true)
48+
editor.destroy()
4749
})
4850

4951
test('emits the full content when clicked', async () => {
@@ -56,4 +58,5 @@ test('emits the full content when clicked', async () => {
5658
wrapper.find('button').trigger('click')
5759
await nextTick()
5860
expect(listen).toHaveBeenCalledWith({ content: text })
61+
editor.destroy()
5962
})

src/tests/extensions/Search.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { describe, expect, it } from 'vitest'
6+
import { afterAll, describe, expect, it } from 'vitest'
77
import Search from '../../extensions/Search'
88
import HardBreak from '../../nodes/HardBreak.js'
99
import { searchDecorationsPluginKey } from '../../plugins/searchDecorations.js'
@@ -13,6 +13,10 @@ import createCustomEditor from '../testHelpers/createCustomEditor'
1313
describe('editor search highlighting', () => {
1414
const editor = createCustomEditor(lorem, [Search, HardBreak])
1515

16+
afterAll(() => {
17+
editor.destroy()
18+
})
19+
1620
it('can highlight a match', () => {
1721
const searchQuery = 'Lorem'
1822
editor.commands.setSearchQuery(searchQuery)

src/tests/markdown.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,5 +334,6 @@ describe('Trailing nodes', () => {
334334
const serializer = createMarkdownSerializer(tiptap.schema)
335335
const md = serializer.serialize(tiptap.state.doc)
336336
expect(md).toBe(source)
337+
tiptap.destroy()
337338
})
338339
})

src/tests/marks/Link.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('Link extension integrated in the editor', () => {
1313
[Link],
1414
)
1515
expect(editor.commands).toHaveProperty('insertOrSetLink')
16+
editor.destroy()
1617
})
1718

1819
it('should update link if anchor has mark', () => {
@@ -23,6 +24,7 @@ describe('Link extension integrated in the editor', () => {
2324
editor.commands.setTextSelection(3)
2425
editor.commands.insertOrSetLink('updated.de', { href: 'updated.de' })
2526
expect(editor.getJSON()).toMatchSnapshot()
27+
editor.destroy()
2628
})
2729

2830
it('Should only update link the anchor is on', () => {
@@ -33,6 +35,7 @@ describe('Link extension integrated in the editor', () => {
3335
editor.commands.setTextSelection(3)
3436
editor.commands.insertOrSetLink('updated.de', { href: 'updated.de' })
3537
expect(editor.getJSON()).toMatchSnapshot()
38+
editor.destroy()
3639
})
3740

3841
it('should insert new link if none at anchor', () => {
@@ -45,5 +48,6 @@ describe('Link extension integrated in the editor', () => {
4548
href: 'https://nextcloud.com',
4649
})
4750
expect(editor.getJSON()).toMatchSnapshot()
51+
editor.destroy()
4852
})
4953
})

src/tests/marks/Underline.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ describe('Underline extension integrated in the editor', () => {
2323
it('is not active by default', () => {
2424
const editor = createCustomEditor('<p>Test</p>', [Underline])
2525
expect(editor.isActive('underline')).toBe(false)
26+
editor.destroy()
2627
})
2728

2829
it('is active within <u> tags', () => {
2930
const editor = createCustomEditor('<p><u>Test</u></p>', [Underline])
3031
expect(editor.isActive('underline')).toBe(true)
32+
editor.destroy()
3133
})
3234
})

src/tests/nodes/TaskItem.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('TaskItem extension', () => {
2323
const editor = createCustomEditor('', [Markdown, TaskList, TaskItem])
2424
const taskItem = editor.schema.nodes.taskItem
2525
expect(taskItem.spec.toMarkdown).toBeDefined()
26+
editor.destroy()
2627
})
2728

2829
it('markdown syntax is preserved through editor', () => {

src/tests/plaintext.spec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const plaintextThroughEditor = (markdown) => {
2121
const content = '<pre>' + escapeHTML(markdown) + '</pre>'
2222
const tiptap = createPlainEditor()
2323
tiptap.commands.setContent(content)
24-
return serializePlainText(tiptap.state.doc) || 'failed'
24+
const plaintext = serializePlainText(tiptap.state.doc) || 'failed'
25+
tiptap.destroy()
26+
return plaintext
2527
}
2628

2729
describe('commonmark as plaintext', () => {
@@ -93,5 +95,6 @@ describe('regression tests', () => {
9395
tiptap.commands.enter()
9496
tiptap.commands.enter()
9597
expect(serializePlainText(tiptap.state.doc)).toEqual('\n\n\n')
98+
tiptap.destroy()
9699
})
97100
})

src/tests/plugins/extractHeadings.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,7 @@ describe('extractHeadings', () => {
6464

6565
const prepareDoc = (content) => {
6666
const editor = createCustomEditor(content, [Heading])
67-
return editor.state.doc
67+
const doc = editor.state.doc
68+
editor.destroy()
69+
return doc
6870
}

src/tests/plugins/searchDecorations.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ describe('search plugin', () => {
7979
})
8080

8181
const testSearch = (content, query, expectedSearchResults) => {
82-
const doc = createCustomEditor(content).state.doc
82+
const editor = createCustomEditor(content)
83+
const doc = editor.state.doc
8384
const searched = runSearch(doc, query)
8485
expect(searched).toHaveProperty('results', expectedSearchResults.results)
8586
expect(highlightResults(doc, searched.results)).toEqual(
8687
highlightResults(doc, expectedSearchResults.results),
8788
)
89+
editor.destroy()
8890
}

0 commit comments

Comments
 (0)