我需要测试一个在浏览器中打开新选项卡的函数
openStatementsReport(contactIds) {
window.open(`a_url_${contactIds}`);
}
Run Code Online (Sandbox Code Playgroud)
我想模拟窗口的open函数,这样我就可以验证正确的URL是否传递给open函数.
使用Jest,我不知道如何模仿窗口.我尝试使用模拟函数设置window.open但这种方式不起作用.以下是测试用例
it('correct url is called', () => {
window.open = jest.fn();
statementService.openStatementsReport(111);
expect(window.open).toBeCalled();
});
Run Code Online (Sandbox Code Playgroud)
但它给了我错误
expect(jest.fn())[.not].toBeCalled()
jest.fn() value must be a mock function or spy.
Received:
function: [Function anonymous]
Run Code Online (Sandbox Code Playgroud)
我应该怎么做测试用例?任何建议或提示表示赞赏
作为一个clojure初学者,我正在阅读clojure代码,让自己熟悉Clojure的语法.下面的代码片段是Ring项目中的一个函数
(defn- request-context
"Create an UploadContext object from a request map."
{:tag UploadContext}
[request encoding]
(reify UploadContext
(getContentType [this] (get-in request [:headers "content-type"]))
(getContentLength [this] (or (req/content-length request) -1))
(contentLength [this] (or (req/content-length request) -1))
(getCharacterEncoding [this] encoding)
(getInputStream [this] (:body request))))
Run Code Online (Sandbox Code Playgroud)
我不清楚的是这条线
{:tag UploadContext}
Run Code Online (Sandbox Code Playgroud)
如果审查一个clojure函数的定义
(defn function-name doc-string? attr-map? [parameter-list]
conditions-map?
(expressions))
Run Code Online (Sandbox Code Playgroud)
我猜(但不确定)地图应该是"attr-map?".但什么是"attr-map?"?我google了,找不到好的解释.
任何引入"attr-map"的例子或链接?将不胜感激.我也想知道如何在我粘贴的代码中使用attr-map.
使用Clojure,如何生成随机长数?我知道Clojure有一个rand-int函数,但它只适用于整数.如果给定的数字很长,我得到了这个repl错误:
IllegalArgumentException Value out of range for int: 528029243649 clojure.lang.RT.intCast (RT.java:1205)
我想获得一些帮助,以了解有关 Http4korg.http4k.core包中使用的功能接口的 Kotlin 代码片段
typealias HttpHandler = (Request) -> Response
fun interface Filter : (HttpHandler) -> HttpHandler {
companion object
}
Run Code Online (Sandbox Code Playgroud)
我不了解Filter界面,尤其是companion object部分。一个典型的功能界面是这样的
fun interface IntPredicate {
fun accept(i: Int): Boolean
}
Run Code Online (Sandbox Code Playgroud)
你可以创建一个 lambda isEven
val isEven = IntPredicate { it % 2 == 0 }
Run Code Online (Sandbox Code Playgroud)
根据这个简单的例子,看起来接口Filter扩展了另一个接口(HttpHandler) -> HttpHandler?然后它定义了一个函数签名companion object?这样对吗?这部分的companion object真正含义是什么?
对于某些复杂的业务逻辑,我需要使用JPA本机查询(使用Hibernate),我发现显然所有实体属性都需要在本机查询的SELECT子句中。否则,JPA总是抛出
java.sql.SQLException: Column 'xxx' not found.
Run Code Online (Sandbox Code Playgroud)
所以我想知道这是否是必需的,还是因为我找不到任何JPA规范对此而在我的代码/配置中遗漏了什么。我的代码如下:
表架构
CREATE TABLE `casaddress` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`addressLine1` varchar(255) DEFAULT NULL,
`addressLine2` varchar(255) DEFAULT NULL,
`companyId` bigint(20) DEFAULT NULL,
`country` varchar(255) DEFAULT NULL,
`effectiveDate` date DEFAULT NULL,
`occupiedOfficer` varchar(255) DEFAULT NULL,
`postcode` varchar(255) DEFAULT NULL,
`suburb` varchar(255) DEFAULT NULL,
`type` int(11) DEFAULT NULL,
`version` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK616A8A7F1FD01BA8` (`companyId`),
CONSTRAINT `FK616A8A7F1FD01BA8` FOREIGN KEY (`companyId`) REFERENCES `cascompany` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1
Run Code Online (Sandbox Code Playgroud)
JPA实体代码(仅是pojo)
@Entity(name = "CASAddress") …Run Code Online (Sandbox Code Playgroud)