1
0
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:
Bogdan Bodnar
2019-08-23 15:20:22 +02:00
parent 02ca27e49c
commit 7b38c1658c
69 changed files with 2577 additions and 1269 deletions

View 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
View 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
View 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
}
}

View 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 = {};

View 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());
}