diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-08-24 16:53:33 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-08-26 17:27:22 +0200 |
commit | a5e58dc45e2078fa6e2330e78d17a73f92168974 (patch) | |
tree | 508f45285616e97677b5493f10a4e0513d478924 /core/src | |
parent | c0b39bb9095b9e0421314c99d3ff0e149a21c435 (diff) | |
download | nextcloud-server-a5e58dc45e2078fa6e2330e78d17a73f92168974.tar.gz nextcloud-server-a5e58dc45e2078fa6e2330e78d17a73f92168974.zip |
test: Migrated all Jest tests to vitest
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/tests/OC/requesttoken.spec.js | 22 | ||||
-rw-r--r-- | core/src/tests/components/ContactsMenu/Contact.spec.js | 1 | ||||
-rw-r--r-- | core/src/tests/views/ContactsMenu.spec.js | 15 |
3 files changed, 17 insertions, 21 deletions
diff --git a/core/src/tests/OC/requesttoken.spec.js b/core/src/tests/OC/requesttoken.spec.js index 456b304df56..36833742d14 100644 --- a/core/src/tests/OC/requesttoken.spec.js +++ b/core/src/tests/OC/requesttoken.spec.js @@ -3,10 +3,12 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { subscribe, unsubscribe } from '@nextcloud/event-bus' - +import { beforeEach, describe, expect, test, vi } from 'vitest' import { manageToken, setToken } from '../../OC/requesttoken.js' +const eventbus = vi.hoisted(() => ({ emit: vi.fn() })) +vi.mock('@nextcloud/event-bus', () => eventbus) + describe('request token', () => { let emit @@ -14,7 +16,7 @@ describe('request token', () => { const token = 'abc123' beforeEach(() => { - emit = jest.fn() + emit = vi.fn() const head = window.document.getElementsByTagName('head')[0] head.setAttribute('data-requesttoken', token) @@ -32,22 +34,10 @@ describe('request token', () => { }) describe('@nextcloud/auth integration', () => { - let listener - - beforeEach(() => { - listener = jest.fn() - - subscribe('csrf-token-update', listener) - }) - - afterEach(() => { - unsubscribe('csrf-token-update', listener) - }) - test('fires off an event for @nextcloud/auth', () => { setToken('123') - expect(listener).toHaveBeenCalledWith({ token: '123' }) + expect(eventbus.emit).toHaveBeenCalledWith('csrf-token-update', { token: '123' }) }) }) diff --git a/core/src/tests/components/ContactsMenu/Contact.spec.js b/core/src/tests/components/ContactsMenu/Contact.spec.js index bf474505009..e83f75bfd15 100644 --- a/core/src/tests/components/ContactsMenu/Contact.spec.js +++ b/core/src/tests/components/ContactsMenu/Contact.spec.js @@ -3,6 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { describe, expect, it } from 'vitest' import { shallowMount } from '@vue/test-utils' import Contact from '../../../components/ContactsMenu/Contact.vue' diff --git a/core/src/tests/views/ContactsMenu.spec.js b/core/src/tests/views/ContactsMenu.spec.js index 6df73fa1827..084c3215e47 100644 --- a/core/src/tests/views/ContactsMenu.spec.js +++ b/core/src/tests/views/ContactsMenu.spec.js @@ -3,13 +3,18 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -import axios from '@nextcloud/axios' import { mount, shallowMount } from '@vue/test-utils' +import { describe, expect, it, vi } from 'vitest' import ContactsMenu from '../../views/ContactsMenu.vue' -jest.mock('@nextcloud/axios', () => ({ - post: jest.fn(), +const axios = vi.hoisted(() => ({ + post: vi.fn(), +})) +vi.mock('@nextcloud/axios', () => ({ default: axios })) + +vi.mock('@nextcloud/auth', () => ({ + getCurrentUser: () => ({ uid: 'user', isAdmin: false, displayName: 'User' }), })) describe('ContactsMenu', function() { @@ -39,7 +44,7 @@ describe('ContactsMenu', function() { it('shows error view when contacts can not be loaded', async () => { const view = mount(ContactsMenu) axios.post.mockResolvedValue({}) - jest.spyOn(console, 'error').mockImplementation(() => {}) + vi.spyOn(console, 'error').mockImplementation(() => {}) try { await view.vm.handleOpen() @@ -56,7 +61,7 @@ describe('ContactsMenu', function() { it('shows text when there are no contacts', async () => { const view = mount(ContactsMenu) - axios.post.mockResolvedValue({ + axios.post.mockResolvedValueOnce({ data: { contacts: [], contactsAppEnabled: false, |