Error while running unit test case with Jest-Enzyme
I am trying to write a unit test case for a login page. I am unable to add other test cases as I am getting the error on the first line itself. Below is my login.spec.tsx code
import LoginPage from '../pages/login';
import { shallow } from 'enzyme';
describe('Login button', () => {
it('should login successfully', () => {
const button = shallow(<LoginPage />); // Error on this line
});
})
Below is the error which I am getting. But if I comment out the 'shallow' code, the test case is passed.
E:React Js Projectdoorstopsrc__tests__login.spec.tsx:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import LoginPage from '../pages/login';
^^^^^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
Below is my package.json. Below are all the installations and dependencies I have done in my project.
{
"name": "cliq-ravendb",
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/polyfill": "^7.2.5",
"@types/node": "10.12.9",
"@types/react": "16.7.6",
"@types/react-dom": "16.0.9",
"@types/react-router-dom": "^4.3.1",
"antd": "^3.11.2",
"apollo-cache-inmemory": "^1.3.11",
"apollo-client": "^2.4.7",
"apollo-link": "^1.2.4",
"apollo-link-error": "^1.1.2",
"apollo-link-http": "^1.5.7",
"babel-jest": "^23.6.0",
"graphql": "^14.0.2",
"graphql-tag": "^2.10.0",
"node-sass": "^4.11.0",
"react": "^16.6.3",
"react-apollo": "^2.3.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.1",
"typescript": "3.1.6"
},
"scripts": {
"dev": "concurrently "npm run start-frontend" "npm run start-server"",
"build": "craco build && cd backend && npm run build",
"start": "node ./build/backend/server.js",
"test": "./node_modules/.bin/jest",
"start-frontend": "craco start",
"start-server": "cd backend && npm run dev",
"postinstall": "cd backend && npm install",
"eject": "react-scripts eject"
},
"jest": {
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\.(ts|tsx)$": "<rootDir>/test-preprocessor.ts"
},
"transformIgnorePatterns": [
"/node_modules"
],
"testMatch": [
"**/__tests__/*.(ts|tsx|js)"
]
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"@craco/craco": "^3.2.2",
"@types/enzyme": "^3.1.15",
"@types/enzyme-adapter-react-16": "^1.0.3",
"@types/jest": "^23.3.10",
"concurrently": "^4.1.0",
"craco-antd": "^1.9.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"eslint": "^5.6.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"jest": "^23.6.0",
"jest-enzyme": "^7.0.1",
"jest-fetch-mock": "^2.1.0",
"prettier": "^1.15.2",
"react-dom": "^16.7.0",
"ts-jest": "^23.10.5"
},
"proxy": "http://localhost:5000"
}
Please find me a solution for this problem. Thank you.
reactjs react-native jestjs enzyme
add a comment |
I am trying to write a unit test case for a login page. I am unable to add other test cases as I am getting the error on the first line itself. Below is my login.spec.tsx code
import LoginPage from '../pages/login';
import { shallow } from 'enzyme';
describe('Login button', () => {
it('should login successfully', () => {
const button = shallow(<LoginPage />); // Error on this line
});
})
Below is the error which I am getting. But if I comment out the 'shallow' code, the test case is passed.
E:React Js Projectdoorstopsrc__tests__login.spec.tsx:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import LoginPage from '../pages/login';
^^^^^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
Below is my package.json. Below are all the installations and dependencies I have done in my project.
{
"name": "cliq-ravendb",
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/polyfill": "^7.2.5",
"@types/node": "10.12.9",
"@types/react": "16.7.6",
"@types/react-dom": "16.0.9",
"@types/react-router-dom": "^4.3.1",
"antd": "^3.11.2",
"apollo-cache-inmemory": "^1.3.11",
"apollo-client": "^2.4.7",
"apollo-link": "^1.2.4",
"apollo-link-error": "^1.1.2",
"apollo-link-http": "^1.5.7",
"babel-jest": "^23.6.0",
"graphql": "^14.0.2",
"graphql-tag": "^2.10.0",
"node-sass": "^4.11.0",
"react": "^16.6.3",
"react-apollo": "^2.3.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.1",
"typescript": "3.1.6"
},
"scripts": {
"dev": "concurrently "npm run start-frontend" "npm run start-server"",
"build": "craco build && cd backend && npm run build",
"start": "node ./build/backend/server.js",
"test": "./node_modules/.bin/jest",
"start-frontend": "craco start",
"start-server": "cd backend && npm run dev",
"postinstall": "cd backend && npm install",
"eject": "react-scripts eject"
},
"jest": {
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\.(ts|tsx)$": "<rootDir>/test-preprocessor.ts"
},
"transformIgnorePatterns": [
"/node_modules"
],
"testMatch": [
"**/__tests__/*.(ts|tsx|js)"
]
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"@craco/craco": "^3.2.2",
"@types/enzyme": "^3.1.15",
"@types/enzyme-adapter-react-16": "^1.0.3",
"@types/jest": "^23.3.10",
"concurrently": "^4.1.0",
"craco-antd": "^1.9.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"eslint": "^5.6.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"jest": "^23.6.0",
"jest-enzyme": "^7.0.1",
"jest-fetch-mock": "^2.1.0",
"prettier": "^1.15.2",
"react-dom": "^16.7.0",
"ts-jest": "^23.10.5"
},
"proxy": "http://localhost:5000"
}
Please find me a solution for this problem. Thank you.
reactjs react-native jestjs enzyme
add a comment |
I am trying to write a unit test case for a login page. I am unable to add other test cases as I am getting the error on the first line itself. Below is my login.spec.tsx code
import LoginPage from '../pages/login';
import { shallow } from 'enzyme';
describe('Login button', () => {
it('should login successfully', () => {
const button = shallow(<LoginPage />); // Error on this line
});
})
Below is the error which I am getting. But if I comment out the 'shallow' code, the test case is passed.
E:React Js Projectdoorstopsrc__tests__login.spec.tsx:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import LoginPage from '../pages/login';
^^^^^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
Below is my package.json. Below are all the installations and dependencies I have done in my project.
{
"name": "cliq-ravendb",
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/polyfill": "^7.2.5",
"@types/node": "10.12.9",
"@types/react": "16.7.6",
"@types/react-dom": "16.0.9",
"@types/react-router-dom": "^4.3.1",
"antd": "^3.11.2",
"apollo-cache-inmemory": "^1.3.11",
"apollo-client": "^2.4.7",
"apollo-link": "^1.2.4",
"apollo-link-error": "^1.1.2",
"apollo-link-http": "^1.5.7",
"babel-jest": "^23.6.0",
"graphql": "^14.0.2",
"graphql-tag": "^2.10.0",
"node-sass": "^4.11.0",
"react": "^16.6.3",
"react-apollo": "^2.3.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.1",
"typescript": "3.1.6"
},
"scripts": {
"dev": "concurrently "npm run start-frontend" "npm run start-server"",
"build": "craco build && cd backend && npm run build",
"start": "node ./build/backend/server.js",
"test": "./node_modules/.bin/jest",
"start-frontend": "craco start",
"start-server": "cd backend && npm run dev",
"postinstall": "cd backend && npm install",
"eject": "react-scripts eject"
},
"jest": {
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\.(ts|tsx)$": "<rootDir>/test-preprocessor.ts"
},
"transformIgnorePatterns": [
"/node_modules"
],
"testMatch": [
"**/__tests__/*.(ts|tsx|js)"
]
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"@craco/craco": "^3.2.2",
"@types/enzyme": "^3.1.15",
"@types/enzyme-adapter-react-16": "^1.0.3",
"@types/jest": "^23.3.10",
"concurrently": "^4.1.0",
"craco-antd": "^1.9.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"eslint": "^5.6.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"jest": "^23.6.0",
"jest-enzyme": "^7.0.1",
"jest-fetch-mock": "^2.1.0",
"prettier": "^1.15.2",
"react-dom": "^16.7.0",
"ts-jest": "^23.10.5"
},
"proxy": "http://localhost:5000"
}
Please find me a solution for this problem. Thank you.
reactjs react-native jestjs enzyme
I am trying to write a unit test case for a login page. I am unable to add other test cases as I am getting the error on the first line itself. Below is my login.spec.tsx code
import LoginPage from '../pages/login';
import { shallow } from 'enzyme';
describe('Login button', () => {
it('should login successfully', () => {
const button = shallow(<LoginPage />); // Error on this line
});
})
Below is the error which I am getting. But if I comment out the 'shallow' code, the test case is passed.
E:React Js Projectdoorstopsrc__tests__login.spec.tsx:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import LoginPage from '../pages/login';
^^^^^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
Below is my package.json. Below are all the installations and dependencies I have done in my project.
{
"name": "cliq-ravendb",
"version": "0.1.0",
"private": true,
"dependencies": {
"@babel/polyfill": "^7.2.5",
"@types/node": "10.12.9",
"@types/react": "16.7.6",
"@types/react-dom": "16.0.9",
"@types/react-router-dom": "^4.3.1",
"antd": "^3.11.2",
"apollo-cache-inmemory": "^1.3.11",
"apollo-client": "^2.4.7",
"apollo-link": "^1.2.4",
"apollo-link-error": "^1.1.2",
"apollo-link-http": "^1.5.7",
"babel-jest": "^23.6.0",
"graphql": "^14.0.2",
"graphql-tag": "^2.10.0",
"node-sass": "^4.11.0",
"react": "^16.6.3",
"react-apollo": "^2.3.2",
"react-router-dom": "^4.3.1",
"react-scripts": "2.1.1",
"typescript": "3.1.6"
},
"scripts": {
"dev": "concurrently "npm run start-frontend" "npm run start-server"",
"build": "craco build && cd backend && npm run build",
"start": "node ./build/backend/server.js",
"test": "./node_modules/.bin/jest",
"start-frontend": "craco start",
"start-server": "cd backend && npm run dev",
"postinstall": "cd backend && npm install",
"eject": "react-scripts eject"
},
"jest": {
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\.(ts|tsx)$": "<rootDir>/test-preprocessor.ts"
},
"transformIgnorePatterns": [
"/node_modules"
],
"testMatch": [
"**/__tests__/*.(ts|tsx|js)"
]
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"@craco/craco": "^3.2.2",
"@types/enzyme": "^3.1.15",
"@types/enzyme-adapter-react-16": "^1.0.3",
"@types/jest": "^23.3.10",
"concurrently": "^4.1.0",
"craco-antd": "^1.9.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"eslint": "^5.6.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"jest": "^23.6.0",
"jest-enzyme": "^7.0.1",
"jest-fetch-mock": "^2.1.0",
"prettier": "^1.15.2",
"react-dom": "^16.7.0",
"ts-jest": "^23.10.5"
},
"proxy": "http://localhost:5000"
}
Please find me a solution for this problem. Thank you.
reactjs react-native jestjs enzyme
reactjs react-native jestjs enzyme
edited Dec 31 '18 at 17:48
skyboyer
3,33611128
3,33611128
asked Dec 28 '18 at 5:32
user10790225
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53954071%2ferror-while-running-unit-test-case-with-jest-enzyme%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53954071%2ferror-while-running-unit-test-case-with-jest-enzyme%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown