小编obe*_*lus的帖子

如何转换数学运算符字符以执行其操作?

我想做这样的事情.它给了我一个错误,我猜是因为它op是一个字符串.是否可以将数学运算符的字符串转换为运算符?

def calc(op)
  a = 9
  b = 5
  a op b
end

p calc('-')
p calc('+')
Run Code Online (Sandbox Code Playgroud)

ruby

4
推荐指数
1
解决办法
3051
查看次数

如何模拟readline.createInterface()?

我正在尝试编写一个关于jasmine的测试以检查是否readline.createInterface()已调用,但我一直收到错误消息:TypeError: readline.createInterface is not a function

这是我在游戏课中的大致内容:

run() {
  let rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout,
      prompt: 'OHAI> '
    });

  rl.prompt();
  // ... and the rest ... 
}
Run Code Online (Sandbox Code Playgroud)

和我的测试:

describe('run', () => {
  it('should create readline interface', () => {
    let readline = jasmine.createSpyObj('readline', ['createInterface']);

    game.run();

    expect(readline.createInterface).toHaveBeenCalled();
  });
});
Run Code Online (Sandbox Code Playgroud)

有人有建议吗?

javascript testing mocking readline jasmine

1
推荐指数
1
解决办法
274
查看次数

标签 统计

jasmine ×1

javascript ×1

mocking ×1

readline ×1

ruby ×1

testing ×1