Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw a TypeError instead of the generic Error #32585

Merged
merged 9 commits into from Jan 13, 2021
2 changes: 1 addition & 1 deletion js/src/dropdown.js
Expand Up @@ -263,7 +263,7 @@ class Dropdown extends BaseComponent {
typeof config.reference.getBoundingClientRect !== 'function'
) {
// Popper virtual elements require a getBoundingClientRect method
throw new Error(`${NAME}: Option "reference" provided type "object" without a required "getBoundingClientRect" method.`)
throw new TypeError(`${NAME}: Option "reference" provided type "object" without a required "getBoundingClientRect" method.`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should make the related tests stricter, probably makes sense.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.
Also, changed the NAME to upper case to make the consistency.
Should check for the same in jQueryInterface also? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean should the tests be updated here? (To check if the error is the instance of TypeError)

try {
jQueryMock.fn.dropdown.call(jQueryMock, action)
} catch (error) {
expect(error.message).toEqual(`No method named "${action}"`)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah let's switch any other instances to toThrowError

}

return config
Expand Down
2 changes: 1 addition & 1 deletion js/src/util/index.js
Expand Up @@ -116,7 +116,7 @@ const typeCheckConfig = (componentName, config, configTypes) => {
toType(value)

if (!new RegExp(expectedTypes).test(valueType)) {
throw new Error(
throw new TypeError(
`${componentName.toUpperCase()}: ` +
`Option "${property}" provided type "${valueType}" ` +
`but expected type "${expectedTypes}".`)
Expand Down