Commit caf2e6ac authored by Axel Bocciarelli's avatar Axel Bocciarelli
Browse files

Merge branch 'test' into 'master'

Set-up React Testing Library and write first test

See merge request !425
parents 0dd9797d dc2a47ed
Pipeline #32105 passed with stages
in 8 minutes and 16 seconds
This diff is collapsed.
...@@ -72,6 +72,9 @@ ...@@ -72,6 +72,9 @@
"tinymce": "^4.9.4" "tinymce": "^4.9.4"
}, },
"devDependencies": { "devDependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^10.4.9",
"@testing-library/user-event": "^12.1.3",
"enzyme": "^3.9.0", "enzyme": "^3.9.0",
"enzyme-adapter-react-16": "^1.15.3", "enzyme-adapter-react-16": "^1.15.3",
"es6-plato": "^1.1.6", "es6-plato": "^1.1.6",
...@@ -87,7 +90,7 @@ ...@@ -87,7 +90,7 @@
"typescript": "^3.9.7" "typescript": "^3.9.7"
}, },
"jest": { "jest": {
"resetMocks": true, "clearMocks": true,
"transformIgnorePatterns": [ "transformIgnorePatterns": [
"/node_modules/(?!lodash-es)/.*" "/node_modules/(?!lodash-es)/.*"
] ]
......
import '@testing-library/jest-dom/extend-expect';
// Monkey-patch `console.warn` to silence React methods deprecation warning
// => remove once Bootstrap and `react-bootstrap` have been updated
const warn = console.warn;
console.warn = (param, ...rest) => {
if (
typeof param !== 'string' ||
!/(componentWillMount|componentWillReceiveProps)/.test(param)
) {
warn(param, ...rest);
}
};
import React from 'react';
import { render } from '@testing-library/react';
import { CacheProvider } from 'rest-hooks';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import promise from 'redux-promise-middleware';
import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import reducers from './reducers';
import App from './App';
export function renderApp(ui, options = {}) {
const { initialState, initialRoute = '/', ...renderOptions } = options;
const store = createStore(
reducers,
applyMiddleware(thunk, promise),
initialState
);
function Wrapper() {
return (
<CacheProvider>
<Provider store={store}>
<MemoryRouter initialEntries={[initialRoute]}>
<App />
</MemoryRouter>
</Provider>
</CacheProvider>
);
}
return render(ui, { wrapper: Wrapper, ...renderOptions });
}
// Re-export everything to allow importing RTL functions through `test-utils`
export * from '@testing-library/react';
// import React from 'react'; import { renderApp } from '../test-utils';
// import ReactDOM from 'react-dom';
// import App from './App';
// it('renders without crashing', () => { test('renders login page', () => {
// const div = document.createElement('div'); const { queryByRole } = renderApp();
// ReactDOM.render(<App />, div); expect(queryByRole('heading', { name: 'Sign in' })).toBeTruthy();
// ReactDOM.unmountComponentAtNode(div);
// });
it('fake test ', () => {
expect(true).toBe(true);
}); });
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment