Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky committed Jan 27, 2025
1 parent ada93ac commit d68380f
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,34 @@ describe('OnChangeGenerator', () => {

expect(emitSpy).not.toHaveBeenCalled()
})

it('should emit a signal with selectedOptions for select elements', () => {
const emitSpy = jest.spyOn(emitter, 'emit')
const target = document.createElement('select')
const option1 = document.createElement('option')
option1.value = 'value1'
option1.label = 'label1'
option1.selected = true
const option2 = document.createElement('option')
option2.value = 'value2'
option2.label = 'label2'
target.append(option1, option2)

const event = new Event('change', { bubbles: true })
Object.defineProperty(event, 'target', { value: target })

unregister = onChangeGenerator.register(emitter)
document.dispatchEvent(event)

expect(emitSpy).toHaveBeenCalledWith(
createInteractionSignal({
eventType: 'change',
listener: 'onchange',
target: expect.any(Object),
change: {
selectedOptions: [{ value: 'value1', label: 'label1' }],
},
})
)
})
})

0 comments on commit d68380f

Please sign in to comment.