QA & Testing w/Chai - Were the last 2 tests ever fixed?

The last three exercises are taking an unreasonable amount of time for me. #23 only worked when I did something differently from what the instructions said, and in task #24 I get all the tests to pass except for, ironically, the test that reads “All tests should pass.”

And the error message I get ( AssertionError [ERR_ASSERTION]: No open window with an HTML document ) has nothing to do with what the instructions cover, so I don’t know how to fix it.

I’ve read many forum posts as old as 3-4 years of people running into the same issue. In some cases, it’s because of Replit. In others, it’s because they’re running code locally. I’ve copied and pasted code which other users said had worked for them (only to make sure, because it was pretty much identical to my own code), and I keep getting the damn “no open window…” error.
I hate to be the “Well, my code is fine so the tests must be broken” guy, but I already wasted a lot of time on exercise #23 and enough people have had issues with these exercises for me to reasonably assume they’re faulty. Could someone confirm if this is the case? It’s already 2 am here so I’m calling it a day.

My code:

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

suite('Functional Tests with Zombie.js', 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('"Famous Italian Explorers" form', function () {
    // #5
    test('Submit the surname "Colombo" in the HTML form', function (done) {
      browser.fill('surname', 'Colombo').then(() => {
          browser.pressButton('submit', () => {
          browser.assert.success();
          browser.assert.text('span#name', 'Cristoforo');
          browser.assert.text('span#surname', 'Colombo');
          browser.assert.elements('span#dates', 1);
          done();
        })
      })
    });
    // #6
    test('Submit the surname "Vespucci" in the HTML form', function (done) {
      // assert.fail();

      done();
    });
  });
});

NOTE: I’ve seen a few users say that done() should not be invoked in

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

… but adding those parenthesis was the only way for that exercise (#23, https://www.freecodecamp.org/learn/quality-assurance/quality-assurance-and-testing-with-chai/simulate-actions-using-a-headless-browser ) to pass.

Problem link:

Try changing from using localhost to 0.0.0.0 in the Browser.site code

Browser.site = "http://0.0.0.0:3000";

The

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

error is from invoking the done callback.

Invoking done when it is used as a callback to browser.visit is never correct. That is like invoking an event handler instead of just passing the function definition.


Your code is passing for me for the challenge you linked to. Also, the versions of this challenge I have work just fine locally and on Replit and Gitpod.

I do have to change from using localhost to 0.0.0.0 for the Browser.site code (I think it is some Node IPv6 issue).


Please post a repo with your complete code.

From where are you running the code?

1 Like

If you run this on Replit/Gitpod you should also be able to use the root site URL for the Browser.site

Example:

Browser.site = "https://3000-freecodecam-boilerplate-blablabla.ws-eu108.gitpod.io";

1 Like

Thank you, Lasse,
“changing from using localhost to 0.0.0.0 in the Browser.site code” is what did it. There was no way for me to figure that one out on myself, and I’ve no idea why localhost wasn’t working.

Is possible, I would suggest adding a warning in the fCC lesson, like

If you get an 1) Functional Tests with Zombie.js before all" hook in "Functional Tests with Zombie.js" error, try using http://0.0.0.0:3000 instead of http://localhost:3000

I’ve noticed that you also replied to my other post regarding the previous lesson, and that you put a lot of time into writing your replies, testing things on your end (and reading my posts, which I do realize can be quite lengthy ^^’ ), so I just wanted to let you know that I really appreciate it (Y)

1 Like

I believe it is a more recent issue with newer versions of Node.js, we fixed something related to it in another challenge where we had to accept IPv6 IPs.

You could also force IPv4 in the challenge using the Node dns module and localhost should work again.

// add before the test code
const dns = require('dns');
dns.setDefaultResultOrder('ipv4first');

The way I figured it out was by the error message I got.

TypeError: bind EINVAL 0.0.0.0


I should open an issue for it. Not sure how to best handle it but maybe we just force IPv4 in the boilerplate.

Edit: issue

1 Like