gbowne1 / reactsocialnetwork

Social Media website/app made with React 18 & MUI v5
GNU General Public License v3.0
35 stars 59 forks source link

[TODO] Create Jest unit tests #18

Closed gbowne1 closed 1 year ago

gbowne1 commented 1 year ago

Describe the bug [Test/QA] [TODO] Default Jest tests no longer is working.

To Reproduce

Jest extension in VS Code.

Expected behavior

??

Desktop (please complete the following information):

Additional context Default Jest test App.test.js no longer works. Make some decisions on what tests to create once there is enough structure complete. Make a tests dir??

gbowne1 commented 1 year ago

Current Jest output inside VSCode

Jest (reactsocialnetwork)

[info] auto config:

found:
  rootPath: /media/gbowne1/18656299-5992-400a-a7a4-b6ffc4b0612f/Documents/reactsocialnetwork
  jestCommandLine: npm test --

npm WARN npm npm does not support Node.js v10.24.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
npm WARN npm You can find the latest version at https://nodejs.org/

> reactsocialnetwork@0.1.0 test /media/gbowne1/18656299-5992-400a-a7a4-b6ffc4b0612f/Documents/reactsocialnetwork
> react-scripts test "--testLocationInResults" "--json" "--useStderr" "--outputFile" "/tmp/jest_runner_reactsocialnetwork_1000.json" "--watch" "--no-coverage" "--reporters" "default" "--reporters" "/home/gbowne1/.vscode/extensions/orta.vscode-jest-5.1.0/out/reporter.js" "--colors"

Error: Failed to initialize watch plugin "node_modules/jest-watch-typeahead/filename.js":

  ● Test suite failed to run

    /media/gbowne1/18656299-5992-400a-a7a4-b6ffc4b0612f/Documents/reactsocialnetwork/node_modules/jest-watch-typeahead/filename.js:1
    export { default } from './build/file_name_plugin/plugin.js';
    ^^^^^^

    SyntaxError: Unexpected token export

      at requireOrImportModule (node_modules/@jest/core/node_modules/jest-util/build/requireOrImportModule.js:53:28)
      at watch (node_modules/@jest/core/build/watch.js:337:78)
      at runWatch (node_modules/@jest/core/build/cli/index.js:359:29)

npm ERR! Test failed.  See above for more details.

[error] Jest process "watch-tests" ended unexpectedly

[info] jest test run failed, please see: https://github.com/jest-community/vscode-jest/blob/master/README.md#troubleshooting

> Test run exited at 1/28/2023, 1:33:20 PM <
MihirRajChowdhury commented 1 year ago

[gbowne1] I would like to contribute in this issue but I don't know anything about jest if you can point me to some resources regarding jest that will help in the contribution I will be very thankful

gbowne1 commented 1 year ago

@MihirRajChowdhury

I don't know anything about Jest.

I assume there must be good resources for Jest on YouTube or Stackoverflow.

Its a bit early for unit testing.. but not to early to start learning.

gbowne1 commented 1 year ago

Official Jest site is https://jestjs.io/docs/tutorial-react

gbowne1 commented 1 year ago

A good Jest video is here

https://youtube.com/watch?v=OVNjsIto9xM

MihirRajChowdhury commented 1 year ago

Thank you for sharing the resource I will try to contribute to it if I can learn it

gbowne1 commented 1 year ago

Sure @MihirRajChowdhury. Glad to have help.

gbowne1 commented 1 year ago

Almost time to get in some unit testing with @testing library and Jest.

I planned on learning Unit testing with this app myself

@manuel12 @pawel975 @Dylan-Clarry etc

gbowne1 commented 1 year ago

Getting closer to when we should start doing tests.

manuel12 commented 1 year ago

I think I used Jest shortly some time ago, but don't remember much of it, also don't know how much unit tests we need currently.

Now when it comes to testing the Front-end and the components there and the current functionality (like Login, Event creation, etc) I can recommend to use Cypress https://www.cypress.io/.

I've used it many times on different projects, it's real easy to use and would allow us to do Functional, API, and Visual tests on the app.

gbowne1 commented 1 year ago

I not sure yet totally either but am open to looking into using whatever we can come up with

Jest and React testing library is wired up by default though

manuel12 commented 1 year ago

Ok, I will read about jest used with the react testing library and come up with some tests.

I will start by creating tests to the login process and then we can move on from there.

gbowne1 commented 1 year ago

I feel like most people coming to the project to help with tests will know Jest or the testing lib. If we wanna move from there, we can. Right now the only test we have is the default which is failing.

manuel12 commented 1 year ago

I will have some initial tests soon ready for a PR, so I've assigned the ticket to myself.

gbowne1 commented 1 year ago

I wanna learn Jest and React testing library so it will be good to see our own examples I can use.

The initial default App.test.js only tests that the spinny react logo works