angular - 测试 window.addEventListener("message", (event) => , jest, angular-11
问题描述
我正在尝试为以下函数编写联合测试代码,基本上这个函数是由来自子事件的 IFRAME 加载事件触发的。
uploadDone() {
this.paramObj = this.helper.createIframePayload(this.appStateSnapshot);
const iFrameRef = document.getElementById('iframeLoadOtherApp');
if (iFrameRef == null) return;
const iframeContentWindow: any = (<HTMLIFrameElement>iFrameRef).contentWindow;
iframeContentWindow.postMessage({ message: "getAppData", value: this.paramObj }, window.location.origin);
window.addEventListener("message", (event) => {
if (event.origin !== window.location.origin){
return;
}
if (event.data === 'oldMHLoaded') {
iframeContentWindow.postMessage({ message: "getAppData", value: this.paramObj }, window.location.origin);
}
if (event.data === 'iframeSessionExpire') {
this.store.dispatch(new LogoutAction()).subscribe(() => {
this.router.navigateByUrl('login');
});
}
if (event.data === 'goToHome') {
this.router.navigateByUrl('home');
}
});
}
所以,upto iframeContentWindow.postMessage
,已经过测试,但是window.addEventListener
,我无法测试,需要一些帮助。
解决方案
推荐阅读
- linux - 如何创建一个linux终端ASCII字符标志?
- python - 如何实施 kolmogorov-smirnov 测试以提取适合我的数据的最佳分布?
- azure - 从 ARM 模板中的 Azure 密钥保管库获取最新版本的证书
- node.js - 将原始数据上传到 Google Cloud 功能中的 Firebase 存储桶?
- payara - Payara 4.1.2.181 与 Java 7 的兼容性
- observable - MobX 计算 - 计算值链的协调
- tensorflow - 对 3 维张量的每两个连续行的列求和
- vb.net - 如何将文本字符串转换为 GSM 7 位
- ios - 如何检查子视图控制器是否存在
- javascript - 使用网络工作者的并行排序比串行排序(合并排序)慢