我有一个使用DOM的函数
const trap = {
// ...
init() {
if (document.activeElement === this.firstTabStop) {
return this.lastTabStop.focus();
}
}
}
module.exports = trap.init;
我尝试模拟document.activeElement
,但是它抛出了一个错误。
global.document.activeElement = mockFirstTabStop;
mockFirstTabStop
只是一个函数模拟,但无论我在哪里放置它,错误都是相同的。
TypeError:无法设置仅具有getter的 [object Object] 的活动元素属性
那么,我该如何测试条件来期望调用 this.lastTabStop.focus()
?
return this.lastTabStop.focus();
- undefined