我试图覆盖方法中的Cypress,以便为回调提供一个额外的参数。
Ultimately, my goal is to be able to go
cy.customComm和ThatSetsAValue().within((subject, extra) => {})
这个问题似乎是时间问题。。。每当我试图传递一个非硬编码的值时,它都会以未定义的形式传递。我已经尝试了许多排列,似乎即使在.then()回调中设置变量时,当它到达自定义命令时,它也是未定义的。
这是我的超控:
function within<Subject>(
originalWithinFn: Cypress.Comm和OriginalFnWithSubject< within , Subject>,
prevSubject: Subject,
optionsOrFn: Partial<Cypress.Loggable> | WithinCallback,
fnOrUndefined?: WithinCallback,
){
let fn: WithinCallback;
let options: Partial<Cypress.Loggable> | undefined;
if (optionsOrFn instanceof Function && fnOrUndefined === undefined) {
fn = optionsOrFn;
} else if (fnOrUndefined instanceof Function) {
options = optionsOrFn;
fn = fnOrUndefined;
} else {
throw new Error( Invalid arguments provided to cy.within );
}
return getMostRecentNavigationShorth和().then(mostRecentShorth和 => originalWithinFn(prevSubject, options!, (subject) => fn(subject, mostRecentShorth和)));
}
Cypress.Comm和s.overwrite( within , within);
customComm和ThatSetsAValue()的简化版本
是
return cy.get( foo ).then(() => {mostRecentShorth和 = anObject});
和
function getMostRecentNavigationShorth和() {
return new Cypress.Promise((resolve, reject) => resolve(mostRecentShorth和));
}
我已尝试将中中的返回更改为
return cy.then(() =>
getMostRecentNavigationShorth和()
.then(mostRecentShorth和 =>
originalWithinFn(prevSubject, options!, (subject) => fn(subject, mostRecentShorth和)
)));
以及尝试将cy.then
包装在promise周围(或者使用它来代替promise)。无论我做什么,它在实际执行时仍然是未定义的。
知道我是如何/为什么一直没有定义或如何修复它吗?谢谢