fix(ui): prevent compare with non-existing package#1207
fix(ui): prevent compare with non-existing package#1207danielroe merged 5 commits intonpmx-dev:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📝 WalkthroughWalkthroughThe Enter key handler in the package selector component was changed to trim the input and verify that the trimmed value matches an item in the current filtered results or corresponds to the No Dependency option before calling addPackage. Enter now only adds when the trimmed input is non-empty and a matching item or NO_DEPENDENCY_ID exists. No exported or public signatures were changed. Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
| const emitted = component.emitted('update:modelValue') | ||
| expect(emitted).toBeTruthy() | ||
| expect(emitted![0]![0]).toEqual(['my-package']) | ||
| expect(emitted![0]![0]).toEqual(['lodash']) | ||
| }) |
There was a problem hiding this comment.
Add an explicit guard before indexing emitted arrays.
Line 146–149 and Line 162–165 index into emitted without a concrete length check. This breaks the codebase’s strict type-safety guideline for array indexing.
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
closes #1198