所以基本上我有一个 onbeforeunload 函数来照顾并警告用户是否决定重新加载或关闭选项卡。我的代码如下
useEffect(() => {
//this will prevent users from accidently refreshing / closing tab
window.onbeforeunload = () => {
return "Are you sure you want to do this yada yada yada yada?";
};
}, []);
Run Code Online (Sandbox Code Playgroud)
我试图开玩笑地测试它,但 return 语句从未被执行。我的测试如下
window.location.reload();
expect(window.onbeforeunload).toHaveBeenCalled();
Run Code Online (Sandbox Code Playgroud)
即使我嘲笑 onBeforeunload 它也不起作用。任何帮助表示赞赏。谢谢。
在我的组件中,我检查页面是否重新加载并重定向到另一个页面。我通过以下代码来做到这一点。
useEffect(() => {
//this will prevent users from accidently refreshing / closing tab
window.onbeforeunload = () => {
return "";
};
//check whether user reloaded
if (
window.performance.getEntriesByType("navigation")[0].type === "reload"
) {
openExternalURL(process.env.GATSBY_MARKETING_URL);
}
}, []);
Run Code Online (Sandbox Code Playgroud)
问题是我在 Jest/react-test-library 测试用例中不断收到错误,如下所示
TypeError: window.performance.getEntriesByType is not a function
Run Code Online (Sandbox Code Playgroud)
即使我尝试像下面那样嘲笑它,但没有成功。
window.performance = {
getEntriesByType: jest.fn().mockReturnValue([{ type: "reload" }]),
measure: jest.fn()
};
Run Code Online (Sandbox Code Playgroud)
有人能指出我正确的方向吗?提前致谢。
javascript unit-testing mocking reactjs react-testing-library
我有一个framework7应用程序,并且需要将一个外部页面加载到该应用程序中。这意味着导航栏和所有内容都应保留在顶部,但我应该能够显示正文中外部URL的内容。更像inapp浏览器。
我尝试使用iFrame,但是它不适用于基于https的网址。有什么办法吗?
还要注意,如果我将external类添加到锚标记中,则页面将在新窗口中打开。不在应用内。
我已经以UITableViewCell编程方式完成了它并且在iOS 10中工作得很好.但是在使用iOS 11和XCode 9进行更新之后,它的行为有所不同.布局看起来如下所示.
但是,如果我点击单元格然后重新排列并且看起来很好,如下所示.
这里是代码 UITableViewCell
import UIKit
import SnapKit
class AboutCell: UITableViewCell {
let roleLabel : UILabel = {
var tablelabel = UILabel()
tablelabel.font = UIFont (name: "Avenir Next Medium", size: 22)
tablelabel.textAlignment = .center
tablelabel.clipsToBounds = true
tablelabel.translatesAutoresizingMaskIntoConstraints = false
return tablelabel
}()
let nameLabel : UILabel = {
let tablelabel = UILabel()
tablelabel.font = UIFont (name: "Avenir Next Medium", size: 16)
tablelabel.textAlignment = .center
tablelabel.clipsToBounds = true
tablelabel.translatesAutoresizingMaskIntoConstraints = false
return tablelabel
}()
let …Run Code Online (Sandbox Code Playgroud) javascript ×3
ios ×2
reactjs ×2
unit-testing ×2
gatsby ×1
iframe ×1
jestjs ×1
mocking ×1
safari ×1
swift ×1
uitableview ×1