mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2025-06-16 13:46:16 +02:00
Set babel.
This commit is contained in:
37
src/testUtils/customTestRender.js
Normal file
37
src/testUtils/customTestRender.js
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
*
|
||||
* This is free software, licensed under the GNU General Public License v3.
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
/* eslint import/export: "off" */
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import {UIDReset} from 'react-uid';
|
||||
import {StaticRouter} from 'react-router';
|
||||
import {render} from '@testing-library/react'
|
||||
|
||||
Wrapper.propTypes = {
|
||||
children: PropTypes.oneOfType([
|
||||
PropTypes.arrayOf(PropTypes.node),
|
||||
PropTypes.node
|
||||
])
|
||||
};
|
||||
|
||||
function Wrapper({children}) {
|
||||
return <StaticRouter>
|
||||
<UIDReset>
|
||||
{children}
|
||||
</UIDReset>
|
||||
</StaticRouter>
|
||||
}
|
||||
|
||||
const customTestRender = (ui, options) => render(ui, {wrapper: Wrapper, ...options});
|
||||
|
||||
// re-export everything
|
||||
export * from '@testing-library/react'
|
||||
|
||||
// override render method
|
||||
export {customTestRender as render}
|
11
src/testUtils/index.js
Normal file
11
src/testUtils/index.js
Normal file
@ -0,0 +1,11 @@
|
||||
import * as customTestRender from "./customTestRender";
|
||||
import * as mockWS from "./mockWS";
|
||||
import * as setupGlobals from "./setupGlobals";
|
||||
import * as setupTest from "./setupTest";
|
||||
|
||||
export {
|
||||
customTestRender,
|
||||
mockWS,
|
||||
setupGlobals,
|
||||
setupTest,
|
||||
}
|
18
src/testUtils/mockWS.js
Normal file
18
src/testUtils/mockWS.js
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
*
|
||||
* This is free software, licensed under the GNU General Public License v3.
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
|
||||
// Mock foris WS
|
||||
export class mockedWS {
|
||||
bind() {
|
||||
return this
|
||||
}
|
||||
|
||||
subscribe() {
|
||||
return this
|
||||
}
|
||||
}
|
11
src/testUtils/setupGlobals.js
Normal file
11
src/testUtils/setupGlobals.js
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
*
|
||||
* This is free software, licensed under the GNU General Public License v3.
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
// Fake babel (gettext) used for docs
|
||||
global._ = str => str;
|
||||
global.babel = {format: (str) => str};
|
||||
global.ForisTranslations = {};
|
37
src/testUtils/setupTest.js
Normal file
37
src/testUtils/setupTest.js
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
*
|
||||
* This is free software, licensed under the GNU General Public License v3.
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
|
||||
export function setUpTest() {
|
||||
const mockAxios = require('jest-mock-axios');
|
||||
const moment = require('moment-timezone');
|
||||
|
||||
// Setup axios cleanup
|
||||
global.afterEach(() => {
|
||||
mockAxios.reset();
|
||||
});
|
||||
|
||||
// Mock babel (gettext)
|
||||
window._ = str => str;
|
||||
window.babel = {format: (str) => str};
|
||||
window.ForisTranslations = {};
|
||||
|
||||
// Mock scrollIntoView
|
||||
window.HTMLElement.prototype.scrollIntoView = () => {
|
||||
};
|
||||
|
||||
jest.doMock('moment', () => {
|
||||
moment.tz.setDefault('UTC');
|
||||
return moment;
|
||||
});
|
||||
|
||||
Date.now = jest.fn(() => new Date(Date.UTC(2019, 1, 1, 12, 13, 14)).valueOf());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user