ChickenKyiv / loopback-tutor-intern-8

https://loopback-react-account.herokuapp.com/
https://groceristar.netlify.com/
GNU General Public License v3.0
0 stars 1 forks source link

can you add tests to all our components? #56

Open atherdon opened 6 years ago

atherdon commented 6 years ago

i think it'll be cool feature

chauhannishith commented 6 years ago

I am trying to find tutorials but all i can find is people showing example 2+2 = 4 tobe true. I tried all shallow and enzyme stuff but nothing seems to work, would be helpful if you could find me a working sample which tests the routes and check if components are rendered.(Even the builtin tests dont work so i am pissed off)

atherdon commented 6 years ago

check jest section here: https://medium.com/groceristar/things-that-should-read-and-use-javascript-intern-at-groceristar-april-18-collection-bd6541e9ae28 maybe it'll help

atherdon commented 6 years ago

btw, don't worry - using tests in first time can be not an easy. but later you'll realize how much pain they can solve :) same feeling i have for using raven. but when i spend 3 days in January just in order to find 1 typo in my import script - i became a raven fan.

atherdon commented 6 years ago

tell me if you need some of my help. i want to include a QA tested that will work only on creating jest tests - so it'll be cool if we'll have code for tests

atherdon commented 6 years ago

we can use Jest in our frontend version for checking simple things at our react components, and at server side - where we'll test our custom remote methods

chauhannishith commented 6 years ago

We have two working test files now in frontend, will start with other tests as soon as I understand how these work and also try to organize them in proper way(which might be the standard) as currently one test in each folder is little cumbersome

chauhannishith commented 6 years ago

at server side - where we'll test our custom remote methods

don't know how it works there but will find out that too

chauhannishith commented 6 years ago

can you check the last two commits i made related to tests and tell me which one is right? Do i have to make a call to the database to test the working or i have to mock them in a similar logic

atherdon commented 6 years ago

i like this tests! mockin is great, but calling to a real api should be done too. because this is how we'll test if our api working at right directions. for sure, we don;t need to have covered all api endpoints. but only that paths that we're using. also api endpoints tests should be done at server side. i mean some tests related to frontend, some tests related and important only at server.

btw, i think i find some a bit confusing things. i saw that you're using tests and .text.js version at the same time. 1 way) usually tests_ are stored at the root of the project. so test script can easily work with it. 2 way) is to keep .test.js file with main component in same folder. like folder header has header.js & header.test.js - and it's easy to split components and tests between projects, etc.

so pick only one structure for doing it. but again- tests makes our code really better.

chauhannishith commented 6 years ago

Call to real api has one issue, it needs to make authenticated calls i.e. use real access tokens and userid so i dont think thats possible to do in these tests

atherdon commented 6 years ago

let's create and import some dummy user 0 so we'll be able to auth, and get token that we need. assume this situation(and it's real) we have a recipe-api-server - and their import and models looks like mess right now(i figure it out this just a few days ago). and another backend dev will work on models changes(mostly updating architecture, i.e. relations) - but instead of tracking her commits - we just run calls and see if endpoints, that i was created a year ago for free menu releases - return same value.

atherdon commented 6 years ago

another big picture: backend developer create a PR to our repo: Travis CI run our tests and see if we can add this to our code base and tests were pass. so for this case i think we cannot do it without dummy user, imported into our database...

atherdon commented 6 years ago

29

@chauhannishith does this tests working by calling npm test ? i mean when we publish updates at netlify - and tests running through their deploy process.

atherdon commented 6 years ago