- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 Jest 有点陌生,所以如果这是一个明显的答案,请原谅我,但在滚动浏览文档后我找不到答案。
我有一个函数 (funcA),它将一个不同长度的数组传递给另一个函数 (funcB),具体取决于 funcA
的参数收到。我正在尝试根据我提供给 funcA
的参数来测试传递给 funcB
的数组的长度是否正确。我并不关心数组的内容,只是它有一定的长度。这是我目前的尝试:
// Modules
const funcA = require('./funcA')
// Mock
const funcB = jest.fn(pairs => {
return pairs[0]
})
// Test
test('Should pass array of 3623 length', () => {
const result = funcA(75)
expect(result).toBeInstanceOf(Object)
expect(funcB).toHaveBeenCalledWith(expect.any(Array).toHaveLength(3623))
})
我想尝试使用 any()
如果可以,但以下测试会导致错误:
TypeError: expect.any(...).toHaveLength is not a function
即使我将 expect.any(...)
包装在另一组括号中,我也会收到相同的错误。有什么方法可以实现我想要的吗?
最佳答案
只断言数组长度而忽略数组内容的测试没有什么值(value)。越具体越好。如果需要特定的数组,可以将其指定为夹具。
此断言无法工作,因为 toHaveBeenCalledWith
应该是预期结果,并且不能包含另一个断言 toHaveLength
。
为了用包含任何元素的数组断言 toHaveBeenCalledWith
,它应该是:
expect(funcB).toBeCalledWith(Array(3623).fill(expect.anything()))
另一种选择是直接断言参数:
expect(funcB).toBeCalledWith(expect.any(Array))
expect(funcB.mock.calls[0][0]).toHaveLength(3623))
关于jestjs - 期望数组参数具有设置长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64198066/
我在远程机器上导航基于 Java 的 CLI 菜单,并在 bash 脚本中使用 expect,我试图从输出中提取某些内容而不离开 expect session 。 我的脚本中的 Expect 命令是:
我正在尝试使用 expect.h header 编译用 c 编写的程序。我正在尝试这个: cc -I/usr/include main.c -lexpect -ltcl cc -I/usr/inclu
我正在使用Expect与SSH session 和ERP程序进行自动交互。 而不是依靠正则表达式来捕获我期望脚本中的变量,是否有可能在收到用户的特定击键后将屏幕区域(例如一个字段)捕获为代码中的变量?
我是 PHP 面向对象编程的新手。我有个问题。我写了一个代码,但它不起作用。我知道这很容易,但我想知道它有什么问题。我出现以下错误: 当我尝试在另一个文件中使用它时,我现在遇到了这个错误:( 最佳答
声明了哪些出现了前所未见的错误,并试图找到解决方案。与以前的程序一样奇怪,它使用相同的语法但不会抛出任何错误 这是一个使用游标从表中检索信息,然后将其插入到另一个表中的过程,这样做是为了可以使用其中的
我已经用 CASE 编写了一个查询,但遇到了 () 问题。 select SM.subscriber_name as name , SM.accountType as accountTy
这个问题在这里已经有了答案: Why does removing return give me an error: expected type `()` but found type (1 个回答)
我有一个脚本可以登录服务器并执行一些命令。我需要能够从每个命令中检索返回代码,以确定脚本是否成功。我写了以下脚本,但没有按照我的意愿进行。目标是执行“cd/I/dont/exist”,这会产生错误代码
关闭。 这个问题需要 debugging details 。它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and
我正在运行一个 expect 脚本,它将生成一些来自 stdin 的动态输入。 是否有一种方法/模式可以解决从标准输入读取并将相关输入存储(?)到某处以在后面的步骤中处理/解析的概念? 示例: ./m
我正在运行一个 expect 脚本,该脚本在远程机器上调用多个脚本。这些 shell 脚本返回颜色输出(主要是红色和绿色)。问题是,那些颜色代码进入了我不想要的 log_file 和 STDOUT。我
我正在开发一个脚本,用于对软件安装进行回归测试。期望代码如下。前几行代码在浏览并同意许可证文件的地方运行良好。但是,脚本在“请输入有效许可证文件的路径名:”处停止,并且不执行任何操作。 (注意:手动安
我们创建以下简单的 expect 脚本以运行 netdata-installer.sh 预期脚本是: #!/usr/bin/expect set timeout 20 send "cd /tmp/ne
有人有T_PAAMAYIM_NEKUDOTAYIM吗? 最佳答案 是双冒号运算符 :: (见 list of parser tokens)。 关于PHP 期望 T_PAAMAYIM_NEKUDOTAY
我正在使用 Vercel SWR Hook usrSWR,我希望我可以将数据存储在某个遥远组件的缓存中,而不必使用上下文或其他一些全局状态管理器。 具体来说,我在 IndexPage 中使用 init
我刚刚注意到,如果我添加 if,Spock 不会断言条件。预期块中的子句,如 def myTest() { given: a = true expect: if ( a ) {
我有一个这样的方法: getValues(...args: Array) : Array { return args.map(k => { return this.shared
我正在使用 typescript + jest,并且在创建模拟实现时遇到了一些类型检查问题。例如,我想模拟 Credentials来自 aws-sdk 的对象: import { Credential
我依赖于一个以 Map 作为参数的方法。 public interface Service { void doSomething(Map map); } 我想写一个断言,用适当的 map 内容
我有一个适配器,它有一个方法,它采用可变参数列表,并将其转发给一个在我使用的框架中采用相同参数的方法。我想测试我的适配器是否正确转发了参数。然而,我不希望我的测试知道框架支持哪种参数。 我有一个工作期
我是一名优秀的程序员,十分优秀!