B
B
bengur22021-08-02 13:38:03
Software testing
bengur2, 2021-08-02 13:38:03

How do express.js app tests work?

Deployed this repository locally:
https://gitlab.com/gitlab-org/project-templates/express

The index.js file replaced:

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'bengur2' });  // тут вставил ник
});

module.exports = router;


Ran test:
yarn test

Got error:
Error: expected body '<!DOCTYPE html><html><head><title>bengur2</title><link rel="stylesheet" href="/stylesheets/style.css"></head><body><h1>bengur2</h1><p>Welcome to bengur2</p></body></html>' to match /Welcome to Express/


Well, of course, because in the test.js file I see hardcode:
it('has the default page', function(done) {
    request(app)
      .get('/')
      .expect(/Welcome to Express/, done);
  });


What to do with this test?
As for me, it is not usable.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question