小编Níc*_*sen的帖子

我可以使用Jest使用特定参数模拟函数吗?

我想用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)

javascript unit-testing jestjs

28
推荐指数
5
解决办法
2万
查看次数

如何在 WSL 上安装 Powerline 字体?

我正在使用Windows Subsystem for Linux (WSL 2)Oh My Zsh来拉我的 bash,但我无法让 Ubuntu 终端正确呈现 Powerline 字体。关于如何设置 WSL 以使用这些字体的任何想法?

在此处输入图片说明

vim-powerline oh-my-zsh powerline windows-subsystem-for-linux

9
推荐指数
3
解决办法
1万
查看次数

创建指向视图的外表

是否可以使用Postgres Foreign Data Wrapper创建一个指向视图而不是表的外表?

postgresql postgres-fdw

6
推荐指数
2
解决办法
4744
查看次数