lundi 21 août 2017

In node.js how can I test an object passed being to a rendered file

router.get('/', (req, res) => {
    User.find({}, (err, users) => {
    res.render('users/index', {users: users});
  });
));

There is no problem with the data being rendered on the page.

I am just looking for a way to make an assertion on the {users: users}

Something like the following...

// testfile.js

const user = {name: 'nate'}

beforeEach((done) => {
  User.remove({}).then(() => {
    return User.insert(user);
  }).then(() => done());
});

it('should GET /users page', (done) => {
  request(app)
    .get('/users/')
    .end((err, response) => {
      assert(response.body === user);
      done();
    })
});

Is there a technique for accessing an object that was passed to a page?

Or possibly a library or for this type of assertion?

Aucun commentaire:

Enregistrer un commentaire