我想用Jest模拟一个函数,但只有在使用特定参数调用它时,例如:
function sum(x, y) {
return x + y;
}
// mock sum(1, 1) to return 4
sum(1, 1) // returns 4 (mocked)
sum(1, 2) // returns 3 (not mocked)
Run Code Online (Sandbox Code Playgroud)
Ruby的RSpec库中实现了类似的功能:
class Math
def self.sum(x, y)
return x + y
end
end
allow(Math).to receive(:sum).with(1, 1).and_return(4)
Math.sum(1, 1) # returns 4 (mocked)
Math.sum(1, 2) # returns 3 (not mocked)
Run Code Online (Sandbox Code Playgroud)
我在测试中想要实现的是更好的解耦,假设我想测试一个依赖于的函数sum:
function sum2(x) {
return sum(x, 2);
}
// I don't want to depend on the sum implementation in my …Run Code Online (Sandbox Code Playgroud) 我正在使用Windows Subsystem for Linux (WSL 2)和Oh My Zsh来拉我的 bash,但我无法让 Ubuntu 终端正确呈现 Powerline 字体。关于如何设置 WSL 以使用这些字体的任何想法?
vim-powerline oh-my-zsh powerline windows-subsystem-for-linux
是否可以使用Postgres Foreign Data Wrapper创建一个指向视图而不是表的外表?
javascript ×1
jestjs ×1
oh-my-zsh ×1
postgres-fdw ×1
postgresql ×1
powerline ×1
unit-testing ×1