fix(client): enzyme tests
This commit is contained in:
@ -9,11 +9,13 @@ import {
|
|||||||
timeout,
|
timeout,
|
||||||
catchError
|
catchError
|
||||||
} from 'rxjs/operators';
|
} from 'rxjs/operators';
|
||||||
import { ShallowWrapper, ReactWrapper } from 'enzyme';
|
import { configure, shallow, mount } from 'enzyme';
|
||||||
import Adapter16 from 'enzyme-adapter-react-16';
|
import Adapter16 from 'enzyme-adapter-react-16';
|
||||||
import { isJSEnabledSelector } from '../redux';
|
import { setConfig } from 'react-hot-loader';
|
||||||
import 'chai';
|
import 'chai';
|
||||||
|
|
||||||
|
import { isJSEnabledSelector } from '../redux';
|
||||||
|
|
||||||
// we use two different frames to make them all essentially pure functions
|
// we use two different frames to make them all essentially pure functions
|
||||||
// main iframe is responsible rendering the preview and is where we proxy the
|
// main iframe is responsible rendering the preview and is where we proxy the
|
||||||
// console.log
|
// console.log
|
||||||
@ -45,7 +47,12 @@ const createHeader = (id = mainId) => `
|
|||||||
export const runTestsInTestFrame = (document, tests) =>
|
export const runTestsInTestFrame = (document, tests) =>
|
||||||
defer(() => {
|
defer(() => {
|
||||||
const { contentDocument: frame } = document.getElementById(testId);
|
const { contentDocument: frame } = document.getElementById(testId);
|
||||||
return frame.__runTests(tests);
|
// Enable Stateless Functional Component. Otherwise, enzyme-adapter-react-16
|
||||||
|
// does not work correctly.
|
||||||
|
setConfig({ pureSFC: true });
|
||||||
|
return frame
|
||||||
|
.__runTests(tests)
|
||||||
|
.pipe(tap(() => setConfig({ pureSFC: false })));
|
||||||
});
|
});
|
||||||
|
|
||||||
const createFrame = (document, state, id) => ctx => {
|
const createFrame = (document, state, id) => ctx => {
|
||||||
@ -120,18 +127,8 @@ const writeTestDepsToDocument = frameReady => ctx => {
|
|||||||
// add enzyme
|
// add enzyme
|
||||||
// TODO: do programatically
|
// TODO: do programatically
|
||||||
// TODO: webpack lazyload this
|
// TODO: webpack lazyload this
|
||||||
ctx.document.Enzyme = {
|
configure({ adapter: new Adapter16() });
|
||||||
shallow: (node, options) =>
|
ctx.document.Enzyme = { shallow, mount };
|
||||||
new ShallowWrapper(node, null, {
|
|
||||||
...options,
|
|
||||||
adapter: new Adapter16()
|
|
||||||
}),
|
|
||||||
mount: (node, options) =>
|
|
||||||
new ReactWrapper(node, null, {
|
|
||||||
...options,
|
|
||||||
adapter: new Adapter16()
|
|
||||||
})
|
|
||||||
};
|
|
||||||
// default for classic challenges
|
// default for classic challenges
|
||||||
// should not be used for modern
|
// should not be used for modern
|
||||||
ctx.document.__source = sources && 'index' in sources ? sources['index'] : '';
|
ctx.document.__source = sources && 'index' in sources ? sources['index'] : '';
|
||||||
|
Reference in New Issue
Block a user