Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 向窗类型定义添加角度_Angular_Typescript_Cypress - Fatal编程技术网

Angular 向窗类型定义添加角度

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直接调用我的一些函数来检查它们的输出

在我的测试中,我似乎找不到角度的参考。我看到了一些关于向全局窗口对象添加自定义“角度”属性的信息,但我似乎仍然无法理解


基于上述示例,如何创建自定义属性,以便在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
    // }
  }
}