Skip to content

Commit 8a7f3b3

Browse files
committed
test: added test for initial change event
1 parent dc2d8e9 commit 8a7f3b3

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/unit/composables/useValue.spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,5 +307,52 @@ describe('useValue', () => {
307307

308308
expect(toggle.vm.checked).toBe(false)
309309
})
310+
311+
it('should trigger change event if value is falsy and falseValue is different than value', async () => {
312+
const toggle = createToggle({
313+
value: false,
314+
falseValue: 'off',
315+
})
316+
317+
await nextTick()
318+
319+
expect(toggle.emitted().change[0]).toEqual(['off'])
320+
})
321+
322+
it('should trigger change event if value is truthy and trueValue is different than value', async () => {
323+
const toggle = createToggle({
324+
value: true,
325+
falseValue: 'off',
326+
trueValue: 'on',
327+
})
328+
329+
await nextTick()
330+
331+
expect(toggle.emitted().change[0]).toEqual(['on'])
332+
})
333+
334+
it('should not trigger change event if value is falsy and falseValue is same than value', async () => {
335+
const toggle = createToggle({
336+
value: 'off',
337+
falseValue: 'off',
338+
trueValue: 'on',
339+
})
340+
341+
await nextTick()
342+
343+
expect(toggle.emitted().change).toBeFalsy()
344+
})
345+
346+
it('should not trigger change event if value is falsy and trueValue is same than value', async () => {
347+
const toggle = createToggle({
348+
value: 'on',
349+
falseValue: 'off',
350+
trueValue: 'on',
351+
})
352+
353+
await nextTick()
354+
355+
expect(toggle.emitted().change).toBeFalsy()
356+
})
310357
})
311358
})

0 commit comments

Comments
 (0)