Skip to content
This repository was archived by the owner on Mar 30, 2022. It is now read-only.

Commit 8473eed

Browse files
in the middle of testing babel config
1 parent 79d5824 commit 8473eed

File tree

6 files changed

+3282
-122
lines changed

6 files changed

+3282
-122
lines changed

__tests__/pages/index.test.tsx

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
// import { NextComponentType } from 'next';
3+
import { mount, ReactWrapper } from 'enzyme';
4+
import { act } from 'react-dom/test-utils';
5+
// import App from '../../pages/_app';
6+
import Index from '../../pages/index';
7+
8+
// const AppWrapper = (props = {}) => mount(<App {...props} />);
9+
10+
describe('Pages', () => {
11+
describe('Index', () => {
12+
let TestIndexWrapper: ReactWrapper;
13+
it('should render without throwing an error', () => {
14+
act(() => {
15+
// @ts-ignore
16+
TestIndexWrapper = mount(<Index userAgent="test" />);
17+
});
18+
expect(TestIndexWrapper.find('main').text()).toBe('Your user agent: test');
19+
});
20+
});
21+
});

babel.config.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'next/babel',
5+
{
6+
'styled-jsx': {},
7+
'preset-env': {},
8+
'preset-react': {},
9+
},
10+
],
11+
],
12+
env: {
13+
test: {
14+
presets: [
15+
[
16+
'@babel/preset-env',
17+
{
18+
modules: false,
19+
targets: { node: 'current' },
20+
},
21+
],
22+
'@babel/react',
23+
'@babel/typescript',
24+
],
25+
},
26+
},
27+
};

enzyme.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Enzyme from 'enzyme';
2+
import Adapter from 'enzyme-adapter-react-16';
3+
// Make sure you can use "publicRuntimeConfig" within tests.
4+
5+
// import { setConfig } from 'next/config';
6+
// import config from './next.config';
7+
8+
// setConfig(config);
9+
Enzyme.configure({ adapter: new Adapter() });

jest.config.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// const esModules = ['next', 'enzyme'].join('|');
2+
3+
module.exports = {
4+
moduleFileExtensions: ['ts', 'tsx', 'js'],
5+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|js?|tsx?|ts?)$',
6+
globals: {
7+
NODE_ENV: 'test',
8+
},
9+
snapshotSerializers: ['enzyme-to-json/serializer'],
10+
transform: {
11+
'^.+\\.(j|t)sx?$': 'babel-jest',
12+
},
13+
coveragePathIgnorePatterns: [
14+
'/node_modules/',
15+
'enzyme.js',
16+
'<rootDir>/configs/',
17+
'jest.config.js',
18+
'.json',
19+
'.snap',
20+
],
21+
setupFiles: ['<rootDir>/enzyme.js'],
22+
coverageReporters: ['json', 'lcov', 'text', 'text-summary'],
23+
moduleNameMapper: {
24+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
25+
'<rootDir>/__mocks__/mocks.js',
26+
'\\.(css|less|scss)$': '<rootDir>/__mocks__/mocks.js',
27+
},
28+
};

0 commit comments

Comments
 (0)