Skip to content

Commit 1a45940

Browse files
committed
test(PackageSelector): improve assertions
1 parent b29c8ae commit 1a45940

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

test/nuxt/components/compare/PackageSelector.spec.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ describe('PackageSelector', () => {
2727
mockFetch.mockReset()
2828
mockFetch.mockResolvedValue({
2929
objects: [
30-
{ package: { name: 'lodash', description: 'Lodash modular utilities' } },
31-
{ package: { name: 'underscore', description: 'JavaScript utility library' } },
30+
{
31+
package: { name: 'lodash', description: 'Lodash modular utilities' },
32+
},
33+
{
34+
package: {
35+
name: 'underscore',
36+
description: 'JavaScript utility library',
37+
},
38+
},
3239
],
3340
})
3441
})
@@ -223,9 +230,10 @@ describe('PackageSelector', () => {
223230
if (resultButton) {
224231
await resultButton.trigger('click')
225232
}
226-
// The emit happens via addPackage which updates the model
227-
// Test passes if no errors thrown
228-
expect(true).toBe(true)
233+
234+
const emitted = component.emitted('update:modelValue')
235+
expect(emitted).toBeTruthy()
236+
expect(emitted![0]![0]).toEqual(['lodash'])
229237
})
230238

231239
it('adds package on Enter key', async () => {
@@ -241,7 +249,7 @@ describe('PackageSelector', () => {
241249

242250
const emitted = component.emitted('update:modelValue')
243251
expect(emitted).toBeTruthy()
244-
expect(emitted![0]![0]).toContain('my-package')
252+
expect(emitted![0]![0]).toEqual(['my-package'])
245253
})
246254

247255
it('clears input after adding package', async () => {
@@ -385,7 +393,14 @@ describe('PackageSelector', () => {
385393

386394
it('renders result items with package info', async () => {
387395
mockFetch.mockResolvedValue({
388-
objects: [{ package: { name: 'lodash', description: 'Lodash modular utilities' } }],
396+
objects: [
397+
{
398+
package: {
399+
name: 'lodash',
400+
description: 'Lodash modular utilities',
401+
},
402+
},
403+
],
389404
})
390405

391406
const component = await mountSuspended(PackageSelector, {

0 commit comments

Comments
 (0)