using jest vs react-scripts test










1















js and react newbie...playing around with testing frameworks...here's the code:



 import React from 'react';
// import CheckboxWithLabel from '../CheckboxWithLabel';
import shallow from 'enzyme'; //not installed...

//var x = require ('../CheckboxWithLabel.js');


test('CheckboxWithLabel changes the text after click', () =>
const checkbox = shallow(
<CheckboxWithLabel labelOn="On" labelOff="Off" />
);
expect(checkbox.text()).toEqual('Off');
checkbox.find('input').simulate('change');
expect(checkbox.text()).toEqual('On');
);


react-scripts test error: Cannot find module 'enzyme' from 'checkboxWithLabel-test.js'



jest error:



Jest encountered an unexpected token

SyntaxError: /Users/shriamin/Development/js_prj_react_django_etc/jest_react_demo/my-app/src/__tests__/checkboxWithLabel-test.js: Unexpected token (12:4)

10 | test('CheckboxWithLabel changes the text after click', () => {
11 | const checkbox = shallow(
> 12 | <CheckboxWithLabel labelOn="On" labelOff="Off" />
| ^
13 | );
14 | expect(checkbox.text()).toEqual('Off');
15 | checkbox.find('input').simulate('change');


i have no idea why jest would throw this error...react-scripts test makes sense to me since enzyme is not installed....please tell me does jest suck or am i doing something wrong configuring jest (installed via npm and update package.json).



NOTE: i don't have babel installed...i don't know what that is yet.



thanks










share|improve this question
























  • i don't have babel installed - you don't have to, that's what react-scripts (create-react-app) basically does itself. This likely should be checkboxWithLabel-test.jsx and not checkboxWithLabel-test.js

    – estus
    Nov 15 '18 at 15:25












  • there are multiple problems in this script. It just seems the order in which they are dealt with is not intuitive to me. Yes there is a second problem with how CheckboxWithLabel is defined, however the missing enzyme module at top seems like it would have precedence. I guess I just don't understand that...

    – lilredindy
    Nov 15 '18 at 16:53







  • 1





    Jest is awesome but it wasn't configured properly. The error means that JSX syntax isn't transpiled. I cannot understand the case. How did you come up with malfunctioning setup like this one? create-react-app is supposed to generate a setup with react-scripts that works out of the box. It already uses Jest. If you're trying to set up Jest in addition to react-scripts, you shouldn't do this.

    – estus
    Nov 15 '18 at 18:06







  • 1





    Was there a reason to do this? react-scripts is basically preconfigured setup, this includes preconfigured Jest. react-scripts test runs jest with specific configuration. When you run jest directly, it lacks needed configuration.

    – estus
    Nov 15 '18 at 18:48






  • 1





    I assume this was a tutorial that didn't imply that you already use CRA. In case it implied that, I'd say that's really bad tutorial.

    – estus
    Nov 15 '18 at 19:06















1















js and react newbie...playing around with testing frameworks...here's the code:



 import React from 'react';
// import CheckboxWithLabel from '../CheckboxWithLabel';
import shallow from 'enzyme'; //not installed...

//var x = require ('../CheckboxWithLabel.js');


test('CheckboxWithLabel changes the text after click', () =>
const checkbox = shallow(
<CheckboxWithLabel labelOn="On" labelOff="Off" />
);
expect(checkbox.text()).toEqual('Off');
checkbox.find('input').simulate('change');
expect(checkbox.text()).toEqual('On');
);


react-scripts test error: Cannot find module 'enzyme' from 'checkboxWithLabel-test.js'



jest error:



Jest encountered an unexpected token

SyntaxError: /Users/shriamin/Development/js_prj_react_django_etc/jest_react_demo/my-app/src/__tests__/checkboxWithLabel-test.js: Unexpected token (12:4)

10 | test('CheckboxWithLabel changes the text after click', () => {
11 | const checkbox = shallow(
> 12 | <CheckboxWithLabel labelOn="On" labelOff="Off" />
| ^
13 | );
14 | expect(checkbox.text()).toEqual('Off');
15 | checkbox.find('input').simulate('change');


i have no idea why jest would throw this error...react-scripts test makes sense to me since enzyme is not installed....please tell me does jest suck or am i doing something wrong configuring jest (installed via npm and update package.json).



NOTE: i don't have babel installed...i don't know what that is yet.



thanks










share|improve this question
























  • i don't have babel installed - you don't have to, that's what react-scripts (create-react-app) basically does itself. This likely should be checkboxWithLabel-test.jsx and not checkboxWithLabel-test.js

    – estus
    Nov 15 '18 at 15:25












  • there are multiple problems in this script. It just seems the order in which they are dealt with is not intuitive to me. Yes there is a second problem with how CheckboxWithLabel is defined, however the missing enzyme module at top seems like it would have precedence. I guess I just don't understand that...

    – lilredindy
    Nov 15 '18 at 16:53







  • 1





    Jest is awesome but it wasn't configured properly. The error means that JSX syntax isn't transpiled. I cannot understand the case. How did you come up with malfunctioning setup like this one? create-react-app is supposed to generate a setup with react-scripts that works out of the box. It already uses Jest. If you're trying to set up Jest in addition to react-scripts, you shouldn't do this.

    – estus
    Nov 15 '18 at 18:06







  • 1





    Was there a reason to do this? react-scripts is basically preconfigured setup, this includes preconfigured Jest. react-scripts test runs jest with specific configuration. When you run jest directly, it lacks needed configuration.

    – estus
    Nov 15 '18 at 18:48






  • 1





    I assume this was a tutorial that didn't imply that you already use CRA. In case it implied that, I'd say that's really bad tutorial.

    – estus
    Nov 15 '18 at 19:06













1












1








1








js and react newbie...playing around with testing frameworks...here's the code:



 import React from 'react';
// import CheckboxWithLabel from '../CheckboxWithLabel';
import shallow from 'enzyme'; //not installed...

//var x = require ('../CheckboxWithLabel.js');


test('CheckboxWithLabel changes the text after click', () =>
const checkbox = shallow(
<CheckboxWithLabel labelOn="On" labelOff="Off" />
);
expect(checkbox.text()).toEqual('Off');
checkbox.find('input').simulate('change');
expect(checkbox.text()).toEqual('On');
);


react-scripts test error: Cannot find module 'enzyme' from 'checkboxWithLabel-test.js'



jest error:



Jest encountered an unexpected token

SyntaxError: /Users/shriamin/Development/js_prj_react_django_etc/jest_react_demo/my-app/src/__tests__/checkboxWithLabel-test.js: Unexpected token (12:4)

10 | test('CheckboxWithLabel changes the text after click', () => {
11 | const checkbox = shallow(
> 12 | <CheckboxWithLabel labelOn="On" labelOff="Off" />
| ^
13 | );
14 | expect(checkbox.text()).toEqual('Off');
15 | checkbox.find('input').simulate('change');


i have no idea why jest would throw this error...react-scripts test makes sense to me since enzyme is not installed....please tell me does jest suck or am i doing something wrong configuring jest (installed via npm and update package.json).



NOTE: i don't have babel installed...i don't know what that is yet.



thanks










share|improve this question
















js and react newbie...playing around with testing frameworks...here's the code:



 import React from 'react';
// import CheckboxWithLabel from '../CheckboxWithLabel';
import shallow from 'enzyme'; //not installed...

//var x = require ('../CheckboxWithLabel.js');


test('CheckboxWithLabel changes the text after click', () =>
const checkbox = shallow(
<CheckboxWithLabel labelOn="On" labelOff="Off" />
);
expect(checkbox.text()).toEqual('Off');
checkbox.find('input').simulate('change');
expect(checkbox.text()).toEqual('On');
);


react-scripts test error: Cannot find module 'enzyme' from 'checkboxWithLabel-test.js'



jest error:



Jest encountered an unexpected token

SyntaxError: /Users/shriamin/Development/js_prj_react_django_etc/jest_react_demo/my-app/src/__tests__/checkboxWithLabel-test.js: Unexpected token (12:4)

10 | test('CheckboxWithLabel changes the text after click', () => {
11 | const checkbox = shallow(
> 12 | <CheckboxWithLabel labelOn="On" labelOff="Off" />
| ^
13 | );
14 | expect(checkbox.text()).toEqual('Off');
15 | checkbox.find('input').simulate('change');


i have no idea why jest would throw this error...react-scripts test makes sense to me since enzyme is not installed....please tell me does jest suck or am i doing something wrong configuring jest (installed via npm and update package.json).



NOTE: i don't have babel installed...i don't know what that is yet.



thanks







reactjs jestjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 16:41









skyboyer

4,12811231




4,12811231










asked Nov 15 '18 at 15:23









lilredindylilredindy

217




217












  • i don't have babel installed - you don't have to, that's what react-scripts (create-react-app) basically does itself. This likely should be checkboxWithLabel-test.jsx and not checkboxWithLabel-test.js

    – estus
    Nov 15 '18 at 15:25












  • there are multiple problems in this script. It just seems the order in which they are dealt with is not intuitive to me. Yes there is a second problem with how CheckboxWithLabel is defined, however the missing enzyme module at top seems like it would have precedence. I guess I just don't understand that...

    – lilredindy
    Nov 15 '18 at 16:53







  • 1





    Jest is awesome but it wasn't configured properly. The error means that JSX syntax isn't transpiled. I cannot understand the case. How did you come up with malfunctioning setup like this one? create-react-app is supposed to generate a setup with react-scripts that works out of the box. It already uses Jest. If you're trying to set up Jest in addition to react-scripts, you shouldn't do this.

    – estus
    Nov 15 '18 at 18:06







  • 1





    Was there a reason to do this? react-scripts is basically preconfigured setup, this includes preconfigured Jest. react-scripts test runs jest with specific configuration. When you run jest directly, it lacks needed configuration.

    – estus
    Nov 15 '18 at 18:48






  • 1





    I assume this was a tutorial that didn't imply that you already use CRA. In case it implied that, I'd say that's really bad tutorial.

    – estus
    Nov 15 '18 at 19:06

















  • i don't have babel installed - you don't have to, that's what react-scripts (create-react-app) basically does itself. This likely should be checkboxWithLabel-test.jsx and not checkboxWithLabel-test.js

    – estus
    Nov 15 '18 at 15:25












  • there are multiple problems in this script. It just seems the order in which they are dealt with is not intuitive to me. Yes there is a second problem with how CheckboxWithLabel is defined, however the missing enzyme module at top seems like it would have precedence. I guess I just don't understand that...

    – lilredindy
    Nov 15 '18 at 16:53







  • 1





    Jest is awesome but it wasn't configured properly. The error means that JSX syntax isn't transpiled. I cannot understand the case. How did you come up with malfunctioning setup like this one? create-react-app is supposed to generate a setup with react-scripts that works out of the box. It already uses Jest. If you're trying to set up Jest in addition to react-scripts, you shouldn't do this.

    – estus
    Nov 15 '18 at 18:06







  • 1





    Was there a reason to do this? react-scripts is basically preconfigured setup, this includes preconfigured Jest. react-scripts test runs jest with specific configuration. When you run jest directly, it lacks needed configuration.

    – estus
    Nov 15 '18 at 18:48






  • 1





    I assume this was a tutorial that didn't imply that you already use CRA. In case it implied that, I'd say that's really bad tutorial.

    – estus
    Nov 15 '18 at 19:06
















i don't have babel installed - you don't have to, that's what react-scripts (create-react-app) basically does itself. This likely should be checkboxWithLabel-test.jsx and not checkboxWithLabel-test.js

– estus
Nov 15 '18 at 15:25






i don't have babel installed - you don't have to, that's what react-scripts (create-react-app) basically does itself. This likely should be checkboxWithLabel-test.jsx and not checkboxWithLabel-test.js

– estus
Nov 15 '18 at 15:25














there are multiple problems in this script. It just seems the order in which they are dealt with is not intuitive to me. Yes there is a second problem with how CheckboxWithLabel is defined, however the missing enzyme module at top seems like it would have precedence. I guess I just don't understand that...

– lilredindy
Nov 15 '18 at 16:53






there are multiple problems in this script. It just seems the order in which they are dealt with is not intuitive to me. Yes there is a second problem with how CheckboxWithLabel is defined, however the missing enzyme module at top seems like it would have precedence. I guess I just don't understand that...

– lilredindy
Nov 15 '18 at 16:53





1




1





Jest is awesome but it wasn't configured properly. The error means that JSX syntax isn't transpiled. I cannot understand the case. How did you come up with malfunctioning setup like this one? create-react-app is supposed to generate a setup with react-scripts that works out of the box. It already uses Jest. If you're trying to set up Jest in addition to react-scripts, you shouldn't do this.

– estus
Nov 15 '18 at 18:06






Jest is awesome but it wasn't configured properly. The error means that JSX syntax isn't transpiled. I cannot understand the case. How did you come up with malfunctioning setup like this one? create-react-app is supposed to generate a setup with react-scripts that works out of the box. It already uses Jest. If you're trying to set up Jest in addition to react-scripts, you shouldn't do this.

– estus
Nov 15 '18 at 18:06





1




1





Was there a reason to do this? react-scripts is basically preconfigured setup, this includes preconfigured Jest. react-scripts test runs jest with specific configuration. When you run jest directly, it lacks needed configuration.

– estus
Nov 15 '18 at 18:48





Was there a reason to do this? react-scripts is basically preconfigured setup, this includes preconfigured Jest. react-scripts test runs jest with specific configuration. When you run jest directly, it lacks needed configuration.

– estus
Nov 15 '18 at 18:48




1




1





I assume this was a tutorial that didn't imply that you already use CRA. In case it implied that, I'd say that's really bad tutorial.

– estus
Nov 15 '18 at 19:06





I assume this was a tutorial that didn't imply that you already use CRA. In case it implied that, I'd say that's really bad tutorial.

– estus
Nov 15 '18 at 19:06












1 Answer
1






active

oldest

votes


















0














in package.json change



 "scripts": 
"test": "jest",
,


to the following:



 "scripts": 
"test": "react-scripts test",
,


i.e. don't change to jest in the first place






share|improve this answer























  • i found this (stackoverflow.com/questions/35756479/…) it tells me how to solve the problem with import/export and jest

    – lilredindy
    Nov 16 '18 at 20:07











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322632%2fusing-jest-vs-react-scripts-test%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














in package.json change



 "scripts": 
"test": "jest",
,


to the following:



 "scripts": 
"test": "react-scripts test",
,


i.e. don't change to jest in the first place






share|improve this answer























  • i found this (stackoverflow.com/questions/35756479/…) it tells me how to solve the problem with import/export and jest

    – lilredindy
    Nov 16 '18 at 20:07
















0














in package.json change



 "scripts": 
"test": "jest",
,


to the following:



 "scripts": 
"test": "react-scripts test",
,


i.e. don't change to jest in the first place






share|improve this answer























  • i found this (stackoverflow.com/questions/35756479/…) it tells me how to solve the problem with import/export and jest

    – lilredindy
    Nov 16 '18 at 20:07














0












0








0







in package.json change



 "scripts": 
"test": "jest",
,


to the following:



 "scripts": 
"test": "react-scripts test",
,


i.e. don't change to jest in the first place






share|improve this answer













in package.json change



 "scripts": 
"test": "jest",
,


to the following:



 "scripts": 
"test": "react-scripts test",
,


i.e. don't change to jest in the first place







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 19:02









lilredindylilredindy

217




217












  • i found this (stackoverflow.com/questions/35756479/…) it tells me how to solve the problem with import/export and jest

    – lilredindy
    Nov 16 '18 at 20:07


















  • i found this (stackoverflow.com/questions/35756479/…) it tells me how to solve the problem with import/export and jest

    – lilredindy
    Nov 16 '18 at 20:07

















i found this (stackoverflow.com/questions/35756479/…) it tells me how to solve the problem with import/export and jest

– lilredindy
Nov 16 '18 at 20:07






i found this (stackoverflow.com/questions/35756479/…) it tells me how to solve the problem with import/export and jest

– lilredindy
Nov 16 '18 at 20:07




















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322632%2fusing-jest-vs-react-scripts-test%23new-answer', 'question_page');

);

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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto