摩卡testing案例res.render不工作

我正在编写一个简单的路由testing用例。 我用mochachai-httpsinon来检查是否显示正确的页面。 这是用户提供信息的contact页面。 联系人页面现在再次呈现。 以下是我的testing案例:

 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 a 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 that our test case is 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(); }); }); }); }); 

问题是我得到一个error responseres说:

  Failed to lookup view "contact" in views directory "C:\\Users\\My User\\Documents\\GitHub\\My Project\\test\\views 

所以基本上它searchtest目录内的view 。 有什么办法可以要求查看正确的目录,这是外部testing?