作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 jasmine 上编写测试以检查是否调用了 readline.createInterface()
,但我不断收到一条错误消息:TypeError: readline.createInterface is not一个函数
这是我在游戏课上的大致内容:
run() {
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: 'OHAI> '
});
rl.prompt();
// ... and the rest ...
}
和我的测试:
describe('run', () => {
it('should create readline interface', () => {
let readline = jasmine.createSpyObj('readline', ['createInterface']);
game.run();
expect(readline.createInterface).toHaveBeenCalled();
});
});
有人有什么建议吗?
最佳答案
尝试以下代码(见上文)并使用 rewire
const rewire = require('rewire')
const game = rewire('path/to/game')
describe('run', () => {
it('should create readline interface', () => {
const readline = jasmine.createSpyObj('readline', ['createInterface']);
const revert = game.__set__('readline', readline);
game.run();
expect(readline.createInterface).toHaveBeenCalled();
revert();
});
});
关于javascript - 如何模拟 readline.createInterface()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45524457/
我正在尝试在 jasmine 上编写测试以检查是否调用了 readline.createInterface(),但我不断收到一条错误消息:TypeError: readline.createInter
当使用 readline 接口(interface)时,从 stdin 到 stdout 的所有内容都会打印两次: var rl = require('readline'); var i = rl.c
尝试使用 .csv 文件中的值构建请求正文,但我的点数组未更新。我已经为 on() 函数内部和末尾的点数组完成了 console.log() ,并且值按预期存在。但我在 on() 之外console.
我正在尝试创建一个电子应用程序。在 main.ts 中,我构造了一个我认为相当简单的类(如下),但构造函数不会运行。对 readline.createInterface(inputStream) 的调
我是一名优秀的程序员,十分优秀!