Skip to content

Commit 6d30c37

Browse files
committed
Fix form field not exists check
1 parent 9a1e866 commit 6d30c37

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/form.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,18 @@ export function getFormField({ label, ...options }: FormFieldOptions & CommonOpt
4949
const opts = logAndMute('getFormField', label, options)
5050
return isUndefined(label)
5151
? cy.get('.ant-form-item', opts)
52-
: getFormFieldLabel({ label, ...opts }).closest('.ant-form-item', opts)
52+
: getFormFieldLabel({ label, ...opts })
53+
// Workaround for https://github.com/cypress-io/cypress/issues/21303.
54+
.should(() => {
55+
// This empty assertion prevents Cypress from failing when the label does not exist.
56+
})
57+
.then($label => {
58+
// If the label wasn't found, do the query again but this time with the existence check on.
59+
if ($label.length === 0) {
60+
return getFormFieldLabel({ label, ...opts })
61+
}
62+
return cy.wrap($label).closest('.ant-form-item', opts)
63+
})
5364
}
5465

5566
type FormInputOptions = FormFieldOptions & { type?: FieldType }

0 commit comments

Comments
 (0)