How to access to parent of parent using test method?
See original GitHub issueI know at the moment it’s not possible to access to parent.parent inside test method (+), just wondering is there another approach to have such functionality, let’s say I want the price field be required if type is equal to 1.
tickets: yup
.array()
.of(
yup.object().shape({
title: yup.string().required(),
type: yup.number().required(),
availability: yup
.object()
.shape({
from: yup
.date()
.when(
"to",
(expiryDate: any, schema: yup.DateSchema) =>
expiryDate &&
schema.max(
expiryDate,
"Available From must be before Avalable To"
)
),
to: yup.date()
})
.nullable(true),
priceInfo: yup
.object()
.shape({
price: yup
.mixed()
.test("match", "price is required", function(price) {
console.log(this);
return false;
}),
currency: yup.string(),
fee: yup.number(),
discount: yup.object().shape({
type: yup.number(),
value: yup.number()
})
})
.nullable(true)
})
)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Yup validation access parent.parent - Stack Overflow
You can use the test method available in the https://github.com/jquense/yup#mixedtestname-string ...
Read more >.parent() | Selector Object | Test API | API | Docs - TestCafe
Selector.parent Method ... Returns an array of parent elements, starting with the closest relatives. Syntax. parent. Selector().parent() → Selector.
Read more >Parent Property | TestComplete Documentation
Use an object's Parent property to get its parent by reference. If the object does not have a parent, the property returns an...
Read more >parent | Cypress Documentation
Get the parent DOM element of a set of DOM elements. Please note that .parent() only travels a single level up the DOM...
Read more >Parent Object - ADM Help Centers
Parent.<supported method>. Note: Using the Context object here enables you to access the run-time context of the selected activity and parent activity.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There is a way to find the parent of the parent. Use
context.from. It’s an array of parents:This isn’t correctly typed yet though: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/49512
I found this mentioned here: https://github.com/jquense/yup/issues/735#issuecomment-873828710, but doesn’t seem to be documented for some reason.
This only works on the
parentjust 1 level up. How do you access the sibling of that parent?