-
-
Notifications
You must be signed in to change notification settings - Fork 273
fix(ui): prevent compare with non-existing package #1207
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 all commits
2f7279f
a2f263a
c61c414
dd724de
3c6046a
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 |
|---|---|---|
|
|
@@ -140,12 +140,28 @@ describe('PackageSelector', () => { | |
| }) | ||
|
|
||
| const input = component.find('input') | ||
| await input.setValue('my-package') | ||
| await input.setValue('lodash') | ||
| await input.trigger('keydown', { key: 'Enter' }) | ||
|
|
||
| const emitted = component.emitted('update:modelValue') | ||
| expect(emitted).toBeTruthy() | ||
| expect(emitted![0]![0]).toEqual(['my-package']) | ||
| expect(emitted![0]![0]).toEqual(['lodash']) | ||
| }) | ||
|
Comment on lines
146
to
+149
Contributor
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. Add an explicit guard before indexing emitted arrays. Line 146–149 and Line 162–165 index into Proposed fix- const emitted = component.emitted('update:modelValue')
- expect(emitted).toBeTruthy()
- expect(emitted![0]![0]).toEqual(['lodash'])
+ const emitted = component.emitted('update:modelValue') ?? []
+ expect(emitted.length).toBe(1)
+ expect(emitted[0]?.[0]).toEqual(['lodash'])- const emitted = component.emitted('update:modelValue')
- expect(emitted).toBeTruthy()
- expect(emitted![0]![0]).toEqual(['__no_dependency__'])
+ const emitted = component.emitted('update:modelValue') ?? []
+ expect(emitted.length).toBe(1)
+ expect(emitted[0]?.[0]).toEqual(['__no_dependency__'])As per coding guidelines, "Ensure you write strictly type-safe code, for example by ensuring you always check when accessing an array value by index". Also applies to: 162-165 |
||
|
|
||
| it('adds "no dep" entry on Enter key', async () => { | ||
| const component = await mountSuspended(PackageSelector, { | ||
| props: { | ||
| modelValue: [], | ||
| }, | ||
| }) | ||
|
|
||
| const input = component.find('input') | ||
| await input.setValue('no dep') | ||
| await input.trigger('keydown', { key: 'Enter' }) | ||
|
|
||
| const emitted = component.emitted('update:modelValue') | ||
| expect(emitted).toBeTruthy() | ||
| expect(emitted![0]![0]).toEqual(['__no_dependency__']) | ||
| }) | ||
|
|
||
| it('clears input after adding package', async () => { | ||
|
|
@@ -156,7 +172,7 @@ describe('PackageSelector', () => { | |
| }) | ||
|
|
||
| const input = component.find('input') | ||
| await input.setValue('my-package') | ||
| await input.setValue('lodash') | ||
| await input.trigger('keydown', { key: 'Enter' }) | ||
|
|
||
| // Input should be cleared | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.