-
Notifications
You must be signed in to change notification settings - Fork 639
fix: Improve a couple of error messages for UI components #3625
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ import { | |||||||||||||||
| any, | ||||||||||||||||
| } from '@metamask/superstruct'; | ||||||||||||||||
|
|
||||||||||||||||
| import { nullUnion } from './jsx'; | ||||||||||||||||
| import { | ||||||||||||||||
| enumValue, | ||||||||||||||||
| literal, | ||||||||||||||||
|
|
@@ -18,6 +19,7 @@ import { | |||||||||||||||
| import type { BoxElement } from '../jsx'; | ||||||||||||||||
| import { Footer, Icon, Text, Button, Box } from '../jsx'; | ||||||||||||||||
| import { | ||||||||||||||||
| BoldStruct, | ||||||||||||||||
| BoxStruct, | ||||||||||||||||
| FieldStruct, | ||||||||||||||||
| FooterStruct, | ||||||||||||||||
|
|
@@ -67,6 +69,14 @@ describe('typedUnion', () => { | |||||||||||||||
| BoxStruct, | ||||||||||||||||
| typedUnion([TextStruct, FieldStruct]), | ||||||||||||||||
| ]); | ||||||||||||||||
| const stringUnion = nullUnion([ | ||||||||||||||||
| string(), | ||||||||||||||||
| typedUnion([TextStruct, BoldStruct]), | ||||||||||||||||
| ]); | ||||||||||||||||
| const nonTypedObjectUnion = nullUnion([ | ||||||||||||||||
| typedUnion([TextStruct, BoldStruct]), | ||||||||||||||||
| object({ type: literal('bar') }), | ||||||||||||||||
| ]); | ||||||||||||||||
|
|
||||||||||||||||
| it('validates strictly the part of the union that matches the type', () => { | ||||||||||||||||
| // @ts-expect-error Invalid props. | ||||||||||||||||
|
|
@@ -86,6 +96,23 @@ describe('typedUnion', () => { | |||||||||||||||
| ); | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| it('validates when nested in a union including primitives', () => { | ||||||||||||||||
| // @ts-expect-error Invalid props. | ||||||||||||||||
| const result = validate(Text({}), stringUnion); | ||||||||||||||||
|
|
||||||||||||||||
| expect(result[0]?.message).toBe( | ||||||||||||||||
| 'Expected the value to satisfy a union of `string | union`, but received: [object Object]', | ||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was this message before? This doesn't seem ideal either 😅
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mostly for coverage purposes, not to actually test the error messages. We want to ensure that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. E.g. snaps/packages/snaps-sdk/src/internals/structs.ts Lines 114 to 120 in a8e0d22
|
||||||||||||||||
| ); | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| it('validates when nested in a union including non-typed objects', () => { | ||||||||||||||||
| const result = validate({ type: 'abc' }, nonTypedObjectUnion); | ||||||||||||||||
|
|
||||||||||||||||
| expect(result[0]?.message).toBe( | ||||||||||||||||
| 'Expected the value to satisfy a union of `union | object`, but received: [object Object]', | ||||||||||||||||
| ); | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| it('validates refined elements', () => { | ||||||||||||||||
| const refinedUnionStruct = typedUnion([BoxStruct, FooterStruct]); | ||||||||||||||||
| const result = validate( | ||||||||||||||||
|
|
||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.