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

Tell us what’s happening:

I cant figure out how to resolve the error that is showing in replit. I followed the instruction and consult the hint indicated in the exercise. I hope someone can shed a light on the issue that I have.

 npm start

> automated-testing-app@0.0.1 start /home/runner/boilerplate-mochachai
> node server.js

Listening on port 3000
Running Tests...
Tests are not valid:
ReferenceError: functions is not defined
    at Object.<anonymous> (/home/runner/boilerplate-mochachai/tests/1_unit-tests.js:4:21)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at /home/runner/boilerplate-mochachai/node_modules/mocha/lib/mocha.js:430:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/home/runner/boilerplate-mochachai/node_modules/mocha/lib/mocha.js:427:14)

Your code so far

const chai= require('chai');
const assert =chai.assert;

suite('Unit Tests', functions)()
{
  suite('Basic Assertions', function()
  {
  test('#isNull, #isNotNull', function()
  {
    assert.isNull(null,'This is an optional error description - e.g. null is null');
    assert.isNotNull(1, '1 is not null');
  });
  });
};

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) 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:

You changed the test code structure and broke it in the process.

Revert your code back to its initial state and pay close attention to where the start and end of the functions are and the body of the functions. You can go to the repo to get the starting code to revert it back to the initial state.

https://github.com/freeCodeCamp/boilerplate-mochachai/tree/main/tests

Personally, I would suggest doing this challenge locally. Not only is that more reliable than Replit but with an editor like VS Code you can get better code highlighting. You also have extensions such as indent-rainbow which may help and other quality-of-life extensions.


suite('Unit Tests', functions)()
  1. functions is an non-exsisting identifier. suite takes a function as the second argument suite('Unit Tests', function() {})

  2. In order for this type of function invocation suite()() to work suite would have to be returning a function that is then immediately called.

Thank you for the advise, I’ll try again this time with your recommendation. Thank you!