node.js - mocha test case for res.render not working -
i'm writing simple test case route. i've used mocha
, chai-http
, sinon
check if correct page rendered or not. contact
page user provides info. , contact page rendered again now. below test case :
const chai = require('chai'); const chaihttp = require('chai-http'); const sinon = require('sinon'); const ejs = require('ejs'); var app = require('../app'); var path = require('path'); var fs = require('fs'); var contact = require('../models/contacts'); chai.use(chaihttp); var should = chai.should(); var expect = chai.expect; describe('contact', () => { describe('/post contact', () => { it('it should not post book without pages field', (done) => { var spy = sinon.spy(ejs, '__express'); let contact = { name: "my name", msg: "my msg" } chai.request(app) .post('/contact') .send(contact) .end((err, res) => { console.log(res) // / console.log(__dirname); // console.log(__filname) // var dir = __filename + './views/contact.ejs'; var dir = path.dirname(fs.realpathsync('./'));; console.log(dir) expect(spy.calledwithmatch(dir + '\views\contact.ejs')).to.be.true; //expect(spy.calledwith(dir)).to.be.true; spy.restore(); // tell mocha our test case done. done(); // res.should.have.status(200); //res.should.have.status() // res.should.have.status(200); // res.body.should.be.a('object'); //res.body.should.have.property('errors'); // res.body.errors.should.have.property('pages'); // res.body.errors.pages.should.have.property('kind').eql('required'); done(); }); }); }); });
the problem error response
on res
saying :
failed lookup view "contact" in views directory "c:\\users\\my user\\documents\\github\\my project\\test\\views
so searches view
inside test
directory. there way can ask view proper directory outside test ?
Comments
Post a Comment