Создайте index.d.ts
в cypress/support
со следующим (например, чтобы добавить свойство с именем ng
):
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
// }
}
}
Тогда вы сможете использовать:
cy.get('.some-ng-element').then(($el) => {
const el = $el[0] // get the DOM element from the jquery element
const win = el.ownerDocument.defaultView // get the window from the DOM element
const component = win.ng.probe(el).componentInstance
})