Quality Assurance - JS Assertions

https://replit.com/@Jket/boilerplate-mochachai-My-Repl-5April2023

When I place my URL in the curriculum, it gives me errors and says that my tests have not passed, yet my tests have passed. Please advise.

You’re submitting the wrong link. That is the link to your project code.
The link you need is the live project link, which you will find above your webview window here:

I submitted this link and still didn’t work: https://boilerplate-mochachai-My-Repl-5April2023.jket.repl.co

What is the issue

I have 25 passes. but when I put the link into the curriculum Js Assertion test, it says that i have not passed any tests and shows errors. Please help.

This is the error message I keep getting

Which challenge are you trying to pass exactly? Can you provide a link please?

You’ve changed the brackets on the test suites, which is causing the testing to fail on FCC.
With this bracketing below, you’re effectively closing off the whole test suite after the first test.

suite('Unit Tests', function () {
  suite('Basic Assertions', function () {
    // #1
    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');
       });
    });

Here’s a screenshot of how the code should be bracketed. I’ve redacted solutions to avoid any spoilers. If you remove the unnecessary closing bracket }); above and put it at the very bottom of this test suite (as in this screenshot), your code will pass.

That worked!!! thank you

I was pulling my hair out.

#5

I am having difficutly noticing the error for the “equal” or “notEqual”.

Below is the error message I keep getting. And I don’t know which “Method” they are asking or talking about. Please advise.

It’s your bracketing again. You need to go through your whole file and ensure that it’s all bracketed as follows:

suite('Unit Tests', function () {
  suite('Basic Assertions', function () {
    test('#isNull, #isNotNull', function () {
      // test code
    });
  });

  // -----------------------------------------------------------------------------

  suite('Equality', function () {
    test('#equal, #notEqual', function () {
      // test code
    });
  });

  // -----------------------------------------------------------------------------

  function weirdNumbers ...

  suite('Comparisons', function () {
    test('#isAbove, #isAtMost', function () {
       // test code
    });
  });

  // -----------------------------------------------------------------------------

  suite('Arrays', function () {
    test('#isArray, #isNotArray', function () {
      // test code
    });
  });

  // -----------------------------------------------------------------------------

  const formatPeople ...
  suite('Strings', function () {
    test('#isString, #isNotString', function () {
      // test code
    });
  });

  // -----------------------------------------------------------------------------

  const Car ...
  const Plane ...
 
  suite('Objects', function () {
    test('#property, #notProperty', function () {
      // test code
    });
  });
});

Basically, the main test suite at the top (Unit Tests), should only be closed off at the very bottom of your file. Each other test suite is nested inside this suite and closed off individually. Each test within each test suite is also closed off. You have a few stray brackets which are causing you problems.

When I forked your repl and made the necessary changes, your code passes.

1 Like

ok, I see. so only the first suite ends at the very end, but each of the other suites have their own ending within?

This has been the most challenging assertions unit.

below is the #isAtLeast or #isBelow assertions. What is wrong with this? I keep getting defferent answers to my submission. First all 4 are correct, then all 4 are incorrect, then everytest hasn’t past, then all 4 test have passed except something.

I am working on the Backend side and not sure why I cannot get #2 ‘response == 200’ to work.

This is the error message I keep getting when I run the test

  1. GET hello your_name => “hello Robin”
    Test GET hello with your name:

    response to equal 200

    • expected - actual

    -404
    +200

    at /home/runner/boilerplate-mochachai-My-Repl-5April2023/tests/2_functional-tests.js:45:12
    at Request.callback (node_modules/superagent/lib/node/index.js:716:12)
    at IncomingMessage. (node_modules/superagent/lib/node/index.js:916:18)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

This is not a valid route:

.get('/hello your_name =< Robin')

That is why you’re getting a 404 (not found) error.

The challenge instructions explain how you should set the route:

Within tests/2_functional-tests.js, alter the 'Test GET /hello with your name' test (// #2) to assert the status and the text of the response to make the test pass.

Send your name as a URL query by appending ?name=<your_name> to the route. The endpoint responds with 'hello <your_name>'.

here is my new problem. I feel like I have been on this for a few days and all kind of looks messed up and completely confusing , at this point. Please help.

below is my backend code. I was trying to get all the brackets in place, but seems that the tests are just not working.

const chai = require(‘chai’);
const assert = chai.assert;

const server = require(‘…/server’);

const chaiHttp = require(‘chai-http’);
chai.use(chaiHttp);

suite(‘Functional Tests’, function() {
this.timeout(5000);
suite(‘Integration tests with chai-http’, function() {
// #1
test(‘Test GET /hello with no name’, function(done) {
// Don’t forget the callback…
chai
.request(server)// ‘server’ is the Express App
.keepOpen()
.get(‘/hello?name = Hello Guest’)
//http_method(url). NO NAME in the query!
.end(function(err, res) {
// res is the response object
// Test the status and the text response (see the example above).
// Please follow the order -status, -text. We rely on that in our tests.
// It should respond ‘Hello Guest’
assert.equal(res.status, 200);
assert.equal(res.text, ‘hello Guest’, ‘response should equal “Hello Guest”’);
done();// Always call the ‘done()’ callback when finished.
});
});
});
})

// #2
suite(‘GET /hello with <your_name>’, function() {
this.timeout(5000);
test(‘Test GET /hello with <your_name>’, function(done) {
Chai
.request(server)// ‘server’ is the Express App
.keepOpen()
.get(‘/hello?name = hello <your_name>’)/** <=== Put your name in the query **/
.end(function(err, res) {
//‘res’ is the response object.

    // Test the status and the text response (see the example above).
    // Please follow the order -status, -text. We rely on that in our tests.
    // It should respond 'Hello Robin'
    assert.equal(res.status, 200, 'response to equal 200');
    assert.equal(res.text, 'hello <your_name>', 'response to equal "Hello Robin"');
    //** <==  Put your_name here **/ 
    done();
    // Always call the 'done()' callback when finished.
  });

});
});

// #3
test(‘Send {surname: “Colombo”}’, function(done) {
chai
.request(server)
.keepOpen()
.put(‘/travellers’)

.end(function(err, res) {
  assert.isUndefined();

  done();
});

});
// #4
test(‘Send {surname: “da Verrazzano”}’, function(done) {
assert.isUndefined();

done();
});

const Browser = require(‘zombie’);

suite(‘Functional Tests with Zombie.js’, function() {
this.timeout(5000);
suite(‘Headless browser’, function() {
test(‘should have a working “site” property’, function() {
assert.isNull(Browser.site);
suite(‘“Famous Italian Explorers” form’, function(done) {
});
});
});
});
// #5
test(‘Submit the surname “Colombo” in the HTML form’, function(done) {
chai

assert.isUndefined();

done();
});

// #6
test(‘Submit the surname “Vespucci” in the HTML form’, function(done) {
chai
assert.isUndefined();

done();
});

If you want to post code on the forum, please use the Preformatted text tool (</> or CTRL+e) and paste your code between the two sets of triple backticks.
Otherwise, your code is pretty unreadable.

If I fork your repl however, I note that your Unit tests are failing because you’re missing a final set of closing brackets, to close off the whole test suite.
Stick }); at the end of your code and you’ll resolve that syntax error.

Then, when your tests run this time, you will run into this error instead:

You defined ‘chai’ elsewhere in your code, so you just need to correct the typo where you’ve tried to use ‘Chai’ instead.

Then, finally, this test still fails because this is not a valid route:

.get('/hello?name = hello <your_name>')

You should be sending a GET request to the ‘/hello’ route, with a query parameter added which has your name as a value (or any name you choose).
The syntax for this is: /hello?parameter=value
Then your test should assert that res.text is equal to a string containing whatever name you entered as a parameter. So, if your name parameter has a value of John, it should return the string ‘hello John’.

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