英文:
cypress `cy.now()` Type 'Promise<any>' has no call signatures
问题
Here's the translated content you requested:
我有这样的 addQuery
:
Cypress.Commands.addQuery('closePopup', (id) => {
const getClosePopup = cy.now('get', `[data-testid="${id}"]`);
return () => {
return getClosePopup();
}
});
而且对于这个我确实得到了这样的错误:
This expression is not callable.
Not all constituents of type 'Promise<any> | ((subject: any) => any)' are callable.
Type 'Promise<any>' has no call signatures.ts(2349)
有任何提示吗?
英文:
I have such addQuery
:
Cypress.Commands.addQuery('closePopup', (id) => {
const getClosePopup = cy.now('get',`[data-testid="${id}"]`);
return () => {
return getClosePopup();
}
});
And fro this i do get such error
This expression is not callable.
Not all constituents of type 'Promise<any> | ((subject: any) => any)' are callable.
Type 'Promise<any>' has no call signatures.ts(2349)
ANy hints on this :/?
答案1
得分: 3
以下是翻译好的内容:
这是因为 cy.now('get',[data-testid="${id}"])
不返回一个函数。
您应该添加一个函数包装器:
Cypress.Commands.addQuery('closePopup', (id) => {
const getClosePopup = () => cy.now('get',`[data-testid="${id}"]`);
return () => {
return getClosePopup();
}
})
或者直接从查询函数中返回表达式
Cypress.Commands.addQuery('closePopup', (id) => {
return () => {
return cy.now('get',`[data-testid="${id}"]`)
}
})
实际上,您只需要一个 jQuery 表达式
Cypress.Commands.addQuery('closePopup', (id) => {
return () => {
return Cypress.$(`[data-testid="${id}"]`)
}
})
英文:
That is because cy.now('get',[data-testid="${id}"])
does not return a function.
You should add a function wrapper:
Cypress.Commands.addQuery('closePopup', (id) => {
const getClosePopup = () => cy.now('get',`[data-testid="${id}"]`);
return () => {
return getClosePopup();
}
})
or return the expression directly from the query function
Cypress.Commands.addQuery('closePopup', (id) => {
return () => {
return cy.now('get',`[data-testid="${id}"]`)
}
})
Really, you just need a jQuery expression
Cypress.Commands.addQuery('closePopup', (id) => {
return () => {
return Cypress.$(`[data-testid="${id}"]`)
}
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论