Fix JS error on cart from postcode validation when 'US' is deselected as an allowed country #13051
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
On the cart page the postcode validation can cause a JS error Uncaught TypeError: Cannot read property 'is_zipcode_optional' of undefined.

To get this error the Magento store has to have deselected 'United States' in the 'Allowed Countries' admin option. Select any country except 'United States' as the default country:- Admin -> Stores -> configuration -> General -> Default Country
If this is the case then Magento will actually cycle through the update() method in app/code/Magento/Ui/view/base/web/js/form/element/region.js twice. Once with the two letter code for the country selected as the 'Default Country' and once with the 'US' country code regardless ofwhether the 'United States' is selected as the default country. If the 'United States' is deselected in the 'Allowed Countries' when the update() method in region.js runs using a value of 'US' the 'option' variable in the update() method is undefined. This code checks for this scenario and returns early.
Manual testing scenarios