Skip to content

Commit 4a212b1

Browse files
committed
Update test
1 parent 92337bc commit 4a212b1

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

.github/workflows/pr.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Build and run tests
2+
3+
'on':
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Install dependencies
18+
run: npm ci
19+
- name: Run build
20+
run: npm run build
21+
- name: Run test
22+
run: npm run test

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const states = new WeakMap()
33
class RemoteInputElement extends HTMLElement {
44
constructor() {
55
super()
6-
const fetch = (e: Event) => fetchResults.bind(null, this, true, e)
7-
const state = {currentQuery: null, oninput: (e: Event) => debounce(fetch(e)), fetch, controller: null}
6+
const fetch = fetchResults.bind(null, this, true)
7+
const state = {currentQuery: null, oninput: debounce((e: Event) => fetch(e)), fetch, controller: null}
88
states.set(this, state)
99
}
1010

@@ -142,13 +142,13 @@ async function fetchWithNetworkEvents(el: Element, url: string, options: Request
142142
}
143143
}
144144

145-
function debounce(callback: () => void) {
145+
function debounce<T>(callback: (args: T) => void) {
146146
let timeout: ReturnType<typeof setTimeout>
147-
return function() {
147+
return function(args: T) {
148148
clearTimeout(timeout)
149149
timeout = setTimeout(() => {
150150
clearTimeout(timeout)
151-
callback()
151+
callback(args)
152152
}, 300)
153153
}
154154
}

test/test.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,24 @@ describe('remote-input', function() {
125125
})
126126

127127
it('check eventType', async function() {
128-
const result = Promise(() => {
129-
element.addEventListener(eventName, (event) => {
130-
assert.equal(event.detail.eventType, 'change')
128+
const result = new Promise(resolve => {
129+
remoteInput.addEventListener('remote-input-success', (event) => {
130+
resolve(event)
131131
}, {once: true})
132132
})
133133
changeValue(input, 'test')
134-
await result
134+
135+
result.then((value) => {
136+
assert.equal(value.detail.eventType, 'change')
137+
})
138+
135139
})
136140
})
137141
})
138142

139143
function changeValue(input, value) {
140144
input.value = value
141-
input.dispatchEvent(new Event('change'))
145+
input.dispatchEvent(new Event('focus'))
142146
}
143147

144148
function nextTick() {

0 commit comments

Comments
 (0)