应用程序代码在调用location.href = "some-url".我想编写一个测试来验证导航重定向是否已经发生.
在jsdom上使用jest,我尝试使用jest mock函数重写location.href setter并且它正在工作.
但是现在我似乎无法在测试清理时恢复location.href属性,并且它在"location.href"上继续传输的其余测试失败了.
it('test navigation happened', () => {
const originalLocationHref = Object.getOwnPropertyDescriptor(window.location, 'href'); // returns undefined
spyFn = jest.fn();
Object.defineProperty(window.location, 'href', {
set: spyFn,
enumerable: true,
configurable: true
});
someAppCodeThatShouldRedirectToSomeUrl();
expect(spyFn).toBeCalledWith('http://some-url'); // this is working
// Cleanup code, not working, because originalLocationHref is undefined
Object.defineProperty(window.location, 'href', originalLocationHref);
});
Run Code Online (Sandbox Code Playgroud)
我错过了什么?为什么Object.getOwnPropertyDescriptor(window.location, 'href');是undefined?
是否有更好的方法来拦截导航事件以进行测试?
谢谢
我想创建一个分为 3 部分的页面布局 - 一列宽度固定,包含两行固定高度。和另一列具有固定宽度,可能包含多个项目(超过适合视图)。
我正在寻找一种方法使页面滚动只影响项目列,以便屏幕左侧(第一列)保持可见。
这是布局的示例图像,以更好地说明含义:

我注意到了这个表达方式
(a!== a && b!== b)
compare = function(a, b) { return a === b || (a !== a && b !== b); };
Run Code Online (Sandbox Code Playgroud)
表达式总是解决为假吗?写这样的东西是什么原因?
我正在尝试使用微软的新库ClrMD来分析崩溃转储和实时进程.
我已经按照.NET框架博客文章(使用附带的.cs文件)中的示例进行操作.
我试图运行样本来分析.dmp文件,该文件取自与样本在同一台机器上运行的程序.
尝试创建运行时对象时,使用以下代码:
ClrRuntime runtime = target.CreateRuntime(dacLocation);
Run Code Online (Sandbox Code Playgroud)
抛出此异常:
消息:加载DAC失败:CreateDacInstance失败0x80131c30
在Microsoft.Diagnostics.Runtime.Desktop.DacLibrary.Init(String dll)
在Microsoft.Diagnostics.Runtime.Desktop.DacLibrary..ctor(DbgEngTarget dataTarget,String dll)
在Microsoft.Diagnostics.Runtime.DbgEngTarget.CreateRuntime(String dacFilename)
在DumpFetch.App..ctor()
有任何想法吗?
我发现在某些情况下运行async-await会慢得多.
<html>
<script>
function makeAPromise() {
return Promise.resolve(Math.random());
}
function usingPromises() {
const before = window.performance.now();
return makeAPromise().then((num) => {
const after = window.performance.now();
console.log('Total (promises): ', after-before, 'ms');
return num;
})
}
async function usingAwait() {
const before = window.performance.now();
const num = await makeAPromise();
const after = window.performance.now();
console.log('Total (await): ', after-before, 'ms');
return num;
}
function runBoth() {
usingAwait();
usingPromises();
}
runBoth();
</script>
<button onclick="usingPromises()">usingPromises</button>
<button onclick="usingAwait()">usingAwait</button>
<button onclick="runBoth()">both</button>
</html>Run Code Online (Sandbox Code Playgroud)
IMO,console.log usingPromises应该打印出类似的结果usingAwait.但实际上,我得到:
总计(承诺):0.25毫秒
总计(等待):2.065毫秒 …
在WinDbg中,我使用!name2ee来查找基类的EEClass和MethodTable.如何查找从该特定类型继承的所有实例?
我有一个内存转储文件,似乎是'System.Drawing.Bitmap'对象的内存泄漏.我有这种类型的多个对象!gcroot无法帮助我识别泄漏的位置.
示例输出:
DOMAIN(0071D148):HANDLE(固定):1513e8:根:03335250(System.Object []) - > 0248e8ec(System.Drawing.Bitmap)
我有一个想法是将图像从内存转储中提取到图像文件中然后,当我可以看到什么是泄漏的图像时,我可以检查围绕该特定位图创建的源代码.
那么,怎么可能将内存写入一个文件,我可以在图像查看器中打开并看到Bitmap对象保持的图像?
此外,如果您有其他想法如何识别泄漏源我很乐意听到它们.
谢谢
javascript ×4
.net ×2
clr ×2
html ×2
windbg ×2
angularjs ×1
async-await ×1
asynchronous ×1
c# ×1
canvas ×1
css ×1
debugging ×1
es6-promise ×1
html5 ×1
jestjs ×1
memory-leaks ×1
sos ×1
testing ×1
unit-testing ×1