Quality Assurance and Testing with Chai - I'm totally lost

Tell us what’s happening:
Describe your issue in detail here.
I am not sure what I am supposed to be learning, and I still don’t understand what assert is or what the arguments mean.

I feel like I’m just randomly guessing at the answers and trying to pattern match without understanding what’s going on or supposed to be going on.

With respect to knowing how much time and effort goes into creating the curriculum ( I created a few early projects myself!), I feel like this section is not up to the teaching standard of most of the other certifications I’ve gone through so far.

But aside from me complaining, is there a good resource to try to learn instead of guessing? (then I can come back and finish when I feel like I know what I’m supposed to be doing).

Update: I typed in “test driven design for dummies” into google and FCC was one of teh top 3 his:

I feel like this article needs to be incorporated into this suite of lessons.

Happy to hear from others about this.

Your code so far

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: Quality Assurance and Testing with Chai - Learn How JavaScript Assertions Work

Link to the challenge:

I have the same feelings

2 Likes

QA testing is an important part of software development, as it helps you to ensure that your code behaves exactly as you expect it to, especially as you develop larger, more complex projects.

There are a number of useful articles out there which help to explain the concepts to you but, essentially, there are two main methodologies when it comes to QA:

  1. Test Driven Development (TDD): A technique whereby test cases are written and run against the currently developed code. The code is rewritten as required until all the tests pass.
    TDD focuses on how the functionality is implemented within the code.

  2. Behaviour Driven Development (BDD): You first define behaviours which you expect from your code (written in simple English or other language common to your team/stakeholders). Then you can write simple automated scripts which can test for these behaviours. Then you write the underlying code and run the tests, rewriting the code as necessary until the desired behaviours are achieved.
    BDD focuses on the behaviour of the application for the end user.

This may not make a lot of sense to you, but that’s fine because this course focuses only on TDD. You don’t need to understand BDD at this point.

Whichever methodology you are using, Mocha and Chai are extremely useful tools which can make your job considerably easier.

In terms of TDD:

Mocha is a feature-rich framework which allows you to build suites of tests to run against your code. You will build these suites within existing JS files. These tests will be run for you by the boilerplate code provided, so for now you don’t need to worry about setting that up yourself.

Chai is a library of assertions, which allow you to test specific features of your code, within the Mocha test suites framework. An assertion is simply a statement which tests if a particular input results in the expected output.

EXAMPLE:

assert.equal(1+1, 2) // test passes
assert.equal(1+2, 2) // test fails

The assertion here simply checks that the first value is equal to the second. In practice, you would be feeding a function and input(s) as the first value and checking that the function returns the expected value. There are all kinds of assertions which you will learn about, but they’re pretty self-explanatory.

There are two types of testing which you will learning about:

  1. Unit Testing: This tests that specific functions or parts of your code work as expected.
  2. Functional Testing: This tests that your app works as expected from the user’s POV. So you test user inputs against the app and ensure that the behaviour of the app is as expected.

This article explains it with a commonly-used analogy:

The FCC QA course basically just runs through the common assertions and concepts, to give you an idea of how it works. You’ll then need to put it into practice properly, writing tests against your own code for the certification projects.

I hope that helps explain it a little for you!

2 Likes

That’s a start thanks for taking the time to put it all together.

Even juts your code example of (1+1,2) being true is more than I knew last evening.

This would be a good introduction before running through the examples.

I’m a little lost in the utility of the course for me at this point, I’m literally guessing at the answers and following patterns without really understanding what I’m doing, or how to write my own.

It seems like this course could use some improvements.

I’ll try to keep track of what I do to learn and maybe submit it as an intro module

The QA course is a little weird to be fair, imho.

The first part is basically like a glossary of assertions, so you get an idea of what assertions can be used and what they mean. It’s not a practical introduction though, as it doesn’t really give you any indication of how (or why) these are used in real-world terms.

Then you have the functional part, which is very brief but gives an overview of how Chai-HTTP works.

Then, a complete break from QA to dive deeper into Node/Express, learning Pug, Passport authentication and web sockets. This bit took me AGES to get my head around and I had to do a LOT of research to really begin to understand how it all works. I took 19pp of notes just about this section alone!

The projects were tough too, though writing the QA tests for them was by far the easiest part. It was only once I’d completed all of the projects that I really felt I understood the point of QA testing properly, as the testing process helped me to improve my code and iron out inconsistencies which I otherwise might not have spotted. The toughest part of the projects for me was writing the logic (e.g. Sudoku solving algorithms).

All in all, this was the toughest certification for me so far, but also the most rewarding.

Good luck!

1 Like

Thanks, I don’t doubt it’s useful and I did actually go through a brief period of time where I was writing React/Mongo/Passport projects using my own version of testing…but it was 5 years ago and a lot of that knowledge is lost, as well as the knowledge of where I learned it!

I feel like the order could be improved to maximize the time spent in learning mode, so I’m happy to hear your perspective on it.

I don’t think FCC’s intention is to lead people down dead ends, but for me, the “glossary” style of challenges like you describe isn’t the best way for me to get reacquainted. But now that I know that I’ll go do some research then come back to it!

If you could help me with one question though…

Since Chai is a library, would there be a more fundamental way to get started, just like you wouldn’t start with react before learning javascript, you shouldn’t learn Chai without first learning … ? Or is it OK to just dive into Chai?

Thanks!

Chai is also a JS library, and if you have a basic grasp of JS and backend stuff (for functional testing), you shouldn’t have any issues. I mean I’m just working through the curriculum in order (starting as a beginner), and I found React way tougher to get my head around than Mocha/Chai.

1 Like

So when I don’t understand something I write it out. I just did a few searches on “what are assertions”, and had an aha moment go off in my head about a game we used to play with my stepdaughter.

So I wrote it all out…it may be wordy and elementary , but for me I think this helped me undesstand what’s going on with testing, and we’ll see if I make better progress ! Let me know what you think if do read it (no obligation though)

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.