diff options
author | François Freitag <mail@franek.fr> | 2021-05-29 23:53:04 +0200 |
---|---|---|
committer | François Freitag <mail@franek.fr> | 2021-05-30 10:44:34 +0200 |
commit | b0847abcc2c55614050951264c906920abd7634f (patch) | |
tree | 2d5d91417b99fad42ca40a08c068d39468dceb7c /core/src/tests | |
parent | 8b3fbe1f0631e9be0844e84210be51cc8a847efd (diff) | |
download | nextcloud-server-b0847abcc2c55614050951264c906920abd7634f.tar.gz nextcloud-server-b0847abcc2c55614050951264c906920abd7634f.zip |
Rewrite requesttoken.spec.js with Jest
[Jest](https://jestjs.io/) is a test runner that focuses on simplicity.
It instruments babel to transform modules and test them.
Using Jest simplifies the existing configuration and allows dropping a
bunch of workarounds, as well as following the shared Babel
configuration for new code.
Signed-off-by: François Freitag <mail@franek.fr>
Diffstat (limited to 'core/src/tests')
-rw-r--r-- | core/src/tests/OC/requesttoken.spec.js | 24 | ||||
-rw-r--r-- | core/src/tests/setup.js | 38 |
2 files changed, 11 insertions, 51 deletions
diff --git a/core/src/tests/OC/requesttoken.spec.js b/core/src/tests/OC/requesttoken.spec.js index 7d17f2f630e..fb550a93ebe 100644 --- a/core/src/tests/OC/requesttoken.spec.js +++ b/core/src/tests/OC/requesttoken.spec.js @@ -3,6 +3,7 @@ * * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author John Molakvoæ <skjnldsv@protonmail.com> + * @author François Freitag <mail@franek.fr> * * @license GNU AGPL version 3 or any later version * @@ -21,42 +22,39 @@ * */ -import { JSDOM } from 'jsdom' import { subscribe, unsubscribe } from '@nextcloud/event-bus' import { manageToken, setToken } from '../../OC/requesttoken' describe('request token', () => { - let dom let emit let manager const token = 'abc123' beforeEach(() => { - dom = new JSDOM() - emit = sinon.spy() - const head = dom.window.document.getElementsByTagName('head')[0] + emit = jest.fn() + const head = window.document.getElementsByTagName('head')[0] head.setAttribute('data-requesttoken', token) - manager = manageToken(dom.window.document, emit) + manager = manageToken(window.document, emit) }) - it('reads the token from the document', () => { - expect(manager.getToken()).to.equal('abc123') + test('reads the token from the document', () => { + expect(manager.getToken()).toBe('abc123') }) - it('remembers the updated token', () => { + test('remembers the updated token', () => { manager.setToken('bca321') - expect(manager.getToken()).to.equal('bca321') + expect(manager.getToken()).toBe('bca321') }) describe('@nextcloud/auth integration', () => { let listener beforeEach(() => { - listener = sinon.spy() + listener = jest.fn() subscribe('csrf-token-update', listener) }) @@ -65,10 +63,10 @@ describe('request token', () => { unsubscribe('csrf-token-update', listener) }) - it('fires off an event for @nextcloud/auth', () => { + test('fires off an event for @nextcloud/auth', () => { setToken('123') - expect(listener).to.have.been.calledWith({ token: '123' }) + expect(listener).toHaveBeenCalledWith({ token: '123' }) }) }) diff --git a/core/src/tests/setup.js b/core/src/tests/setup.js deleted file mode 100644 index 0390a67599b..00000000000 --- a/core/src/tests/setup.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author John Molakvoæ <skjnldsv@protonmail.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -require('jsdom-global')() -const chai = require('chai') -const sinon = require('sinon') -const sinonChai = require('sinon-chai') - -chai.use(sinonChai) -global.expect = chai.expect -global.sinon = sinon - -// https://github.com/vuejs/vue-test-utils/issues/936 -// better fix for "TypeError: Super expression must either be null or -// a function" than pinning an old version of prettier. -// -// https://github.com/vuejs/vue-cli/issues/2128#issuecomment-453109575 -window.Date = Date |