Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorFrançois Freitag <mail@franek.fr>2021-05-30 00:53:04 +0300
committerFrançois Freitag <mail@franek.fr>2021-05-30 11:44:34 +0300
commitb0847abcc2c55614050951264c906920abd7634f (patch)
tree2d5d91417b99fad42ca40a08c068d39468dceb7c /core/src
parent8b3fbe1f0631e9be0844e84210be51cc8a847efd (diff)
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')
-rw-r--r--core/src/tests/OC/requesttoken.spec.js24
-rw-r--r--core/src/tests/setup.js38
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