SERIOUS need of help: "before all" hook in "Functional Tests" error - QA - Issue Tracker

UPDATE: I finally got the tests to run by doing something differently, though I still don’t understand why the code I show in this post doesn’t work. Just a heads-up so that no one wastes their time, unless you’re on the mood for a debugging challenge, of course.

I apologize in advance for the whining, but I think everyone here knows what it’s like when you’ve been sitting in front of your PC for HOURS and still get absolutely nowhere. I’m at my wit’s end with the issue tracker and the Quality Assurance & Adv. Node & Express unit. I have never posted on the forum as often as I have with this one, and I previously completed 6 units.

I really need help here, because I truly don’t know what’s failing, let alone what to do.

I last posted 6 hs ago after solving a different problem and all I had left to do was write the Functional Tests. 6 hours later, I haven’t even been able to run a single test. And the code for my functional-tests file looks EXACTLY like the code that passes all the challenges of “Quality Assurance and Testing with Chai”. It’s the exact same configuration, yet all I get is this error message:

1) Functional Tests
       "before all" hook in "Functional Tests":
     http://0.0.0.0:3000/:script:2
      $(function() {
      ^

ReferenceError: $ is not defined

This is my code, and I must stress that it’s the same code that correctly runs and passes the challenges for the lessons, yet it doesn’t even run now (of course, the only difference are the names of some input fields.

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

const server = require('../server');

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

const Browser = require('zombie');
// Browser.site="http://localhost:3000"; 
Browser.site="http://0.0.0.0:3000";

suite('Functional Tests', function() {
    this.timeout(5000);
    
    const browser = new Browser();

    suiteSetup(function(done) {
        return browser.visit("/", done)
    });

    suite('Headless browser', function () {
        test('should have a working "site" property', function() {
          assert.isNotNull(browser.site);
        });
      });

    suite("POST tests", function () {
        test("Create an issue with every field: POST request to /api/issues/{project}", function (done) {
            browser.fill('input[name="issue_title"]', "Prueba1")
            .fill("issue_text", "This is a test")
            .fill("created_by", "Rodrigo")
            .fill("assigned_to", "Steve")
            .fill("status_text", "A-OK")
            .then(() => {
                browser.pressButton("#testForm1 button[type='submit']", () => {
                    browser.assert.success();
                    browser.assert.text("issue_title", "Prueba1");
                    browser.assert.text("issue_text", "This is a test");
                    browser.assert.text("created_by", "Rodrigo");
                    browser.assert.text("assigned_to", "Steve");
                    browser.assert.text("status_text", "A-OK");
                    done();
                })
            })
            .catch((error) => {
                done(error);
            });
        })
    })
        
});

Please don’t mind whether the test themselves are correctly written. The problem is that they won’t even run.

FAQ:

  1. Tried using Browser.site="http://localhost:3000" instead of Browser.site="http://0.0.0.0:3000";. When I do that, the error message is
  1. Functional Tests
    “before all” hook in “Functional Tests”:
    TypeError: bind EINVAL 0.0.0.0
  1. If I keep Browser.site="http://0.0.0.0:3000" and change the suiteSetup to
suiteSetup(function(done) {
        return browser.visit("/", done()) 
    });

then tests run and one passes, but the second one doesn’t and returns this error message:

AssertionError [ERR_ASSERTION]: No open window with an HTML document

(mind that the second ‘done’ is now ‘done()’ , which I was told should never be the case but was the only thing that worked in a previous project)

  1. and if I use
suiteSetup(function(done) {
        return browser.visit("/", done()) 
    });

and
Browser.site="http://localhost:3000"
the tests run too, but the second one fails with the message:

AssertionError [ERR_ASSERTION]: No INPUT matching 'input[name="issue_title"]'

(it’s a convoluted reference, but I can assure you it’s correct. I’ve also tried it with #issue_title after adding id="issue_title" to the input in .html file, and it doesn’t work either.

Please, I’m sorry to be posting here as often as I have these past two weeks, but I’ve spent an unhealthy amount of hours on this unit and project, and the fact that I can’t even get started when I’m using the exact same configuration that worked in the lessons is very frustrating and desorienting.

1 Like

Hello there,

Out of interest, why are you using zombie? The expectation is you will just use chai with chai-http like in these lessons:

I was looking at the finished 2_functional-tests.js file from the “Quality Assurance and Testing with Chai” course before starting the tests, in order to decide how to tackle the project, and something about zombie using those .fill() and .pressButton() commands just made me go “OK, so I need to use zombie,” as the website requires the user to fill out fields and submit them by pressing the submit button.

Eventually I got things to work by switching to chai, as you mention. I still don’t understand why zombie didn’t even work though (maybe some compatibility issues with dependencies/packages that have been updated since the course was created, deprecated features, who knows…).

1 Like

Possibly this is related to compatibility issues. I was surprised to see Zombie.js has not been updated in 5 years.


If you are still interested, you are probably best reading Zombie’s docs: zombie - npm

Otherwise, nice job getting through the setbacks