【发布时间】:2021-10-30 13:28:46
【问题描述】:
我有以下代码...
App.mjs
import express from "express";
const port = process.env.PORT || 4000;
class CommunicationsApplication{
constructor() {
this.app = CommunicationsApplication.getExpress();
this.app.get('/', (req, res) => {
res.send('Hello World!')
})
this.app.listen(port, () => {
console.log(`listening at http://localhost:${port}`)
})
}
static getExpress(){
return express()
}
}
App.spec.mjs
import {CommunicationsApplication} from "./App.mjs";
import sinon from "sinon";
import {expect} from "chai";
it('Testing to see if test works', () => {
const result = {
get: sinon.fake(),
listen: sinon.fake()
}
sinon.stub(CommunicationsApplication, 'getExpress').callsFake(()=>result)
new CommunicationsApplication();
expect(result.get.callCount).to.eq(1);
expect(result.listen.callCount).to.eq(1);
})
package.json
"type": "module",
...
"test": "nyc mocha --recursive './lib/**/*.spec.mjs' --require esm"
但是当我跑步时,我看到...
✔ Testing to see if test works
为什么我的代码覆盖率不起作用?
1 passing (4ms)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
【问题讨论】:
标签: istanbul ecmascript-next es6-modules