[英]Disable geolocation browser using javascript
我正在使用QUnit編寫集成測試,並且在我的web應用程序中,如果無法使用地理位置,(我使用if (navigator.geolocation)
來檢測是否存在,但是我想禁用它以便在以下情況下實施測試無法使用地理位置。
我嘗試了navigator.geolocation = undefined
但是不幸的是它沒有用。
您不能真正“禁用” navigator.geolocation
因為它是一個只讀屬性。
相反,您可以創建一個包裝器,以檢查某些功能,然后對其進行模擬以進行測試。
var supports = {
geolocation: !!navigator.geolocation // will be `true` if geolocation is defined
};
// In your tests...
supports.geolocation = false;
executeTest();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.