nathanboktae / chai-dom

DOM assertions for the Chai assertion library using vanilla JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to request a URL and asset the value of an h1

jinky32 opened this issue · comments

Hi,

I'm new to mocha and am trying to test an express route and assert the value of the h1 rendered on the page.

I have a test:

const expect  = require('chai').expect;
const assert = require('chai').assert;
const request = require('request');
const app = require('../../app');
const chai = require('chai');
chai.use(require('chai-dom'));
chai.use(chaiHttp);

describe('Story Homepage', function(){
  it('Should have an H1 of My Home Page', function(){
  chai.request(app)
  .get('http://localhost:7777/', function (){
      expect(body.querySelector('h1')).should.have.text('My Home Page');
    // document.querySelector('h1').should.have.text('My Home Page');
     });
  })
});

//some other tests

The good news is that the test passes. The bad news is that it shouldn't. Can anyone advise what I am doing wrong here?

Yes, your test is asynchronous but mocha thinks it's synchronous because you are not returning a promise or taking a done parameter. See the documentation on it.

Hi - Sorry to come back on this but I'm still having issues. Would you be willing to post an answer to https://stackoverflow.com/questions/48331488/using-chai-to-test-value-of-html-element ?