Angular 向窗类型定义添加角度
我正在让Cypress启动并运行。我想让Cypress直接调用我的一些函数来检查它们的输出 在我的测试中,我似乎找不到角度的参考。我看到了一些关于向全局窗口对象添加自定义“角度”属性的信息,但我似乎仍然无法理解Angular 向窗类型定义添加角度,angular,typescript,cypress,Angular,Typescript,Cypress,我正在让Cypress启动并运行。我想让Cypress直接调用我的一些函数来检查它们的输出 在我的测试中,我似乎找不到角度的参考。我看到了一些关于向全局窗口对象添加自定义“角度”属性的信息,但我似乎仍然无法理解 基于上述示例,如何创建自定义属性,以便在Cypress中获得角度对象?在Cypress/support中创建index.d.ts,并使用以下内容(例如添加名为ng的属性): 那么您应该能够使用: cy.get('.some ng元素')。然后($el)=>{ const el=$el[
基于上述示例,如何创建自定义属性,以便在Cypress中获得角度对象?在
Cypress/support
中创建index.d.ts
,并使用以下内容(例如添加名为ng
的属性):
那么您应该能够使用:
cy.get('.some ng元素')。然后($el)=>{
const el=$el[0]//从jquery元素获取DOM元素
const win=el.ownerDocument.defaultView//从DOM元素获取窗口
const component=win.ng.probe(el.componentInstance)
})
Hmm……不起作用。我甚至试着注销win.ng
,但它没有定义。哎呀,忘了。在拥有文档之后查看默认值,告诉我是否有works@JustinYoung有关更好的类型补全,请参阅扩展窗口的更新代码。
interface Window {
ng: {
probe: typeof import("@angular/platform-browser/src/dom/debug/ng_probe").inspectNativeElement
// // un-comment if you need these for some reason:
// ɵcompilerFacade: import("@angular/compiler/src/jit_compiler_facade").CompilerFacadeImpl
// coreTokens: {
// ApplicationRef: import("@angular/core").ApplicationRef
// NgZone: import("@angular/core").NgZone
// }
}
}