Skip to content

Commit

Permalink
Add specs
Browse files Browse the repository at this point in the history
  • Loading branch information
srt32 committed May 28, 2024
1 parent c47e474 commit 1d5282c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/auto-check-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ function makeAbortController() {
}

async function fetchWithNetworkEvents(el: Element, url: string, options: RequestInit): Promise<Response> {
if (options.method === 'GET') {
delete options.body
}
try {
const response = await fetch(url, options)
el.dispatchEvent(new Event('load'))
Expand Down
29 changes: 29 additions & 0 deletions test/auto-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,35 @@ describe('auto-check element', function () {
})
})

describe('using HTTP GET', function () {
let checker
let input

beforeEach(function () {
const container = document.createElement('div')
container.innerHTML = `
<auto-check src="/success" http-method="GET" required>
<input>
</auto-check>`
document.body.append(container)

checker = document.querySelector('auto-check')
input = checker.querySelector('input')
})

afterEach(function () {
document.body.innerHTML = ''
checker = null
input = null
})

it('validates input with successful server response with GET', async function () {
triggerInput(input, 'hub')
await once(input, 'auto-check-complete')
assert.isTrue(input.checkValidity())
})
})

describe('network lifecycle events', function () {
let checker
let input
Expand Down
2 changes: 1 addition & 1 deletion web-test-runner.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default {
middleware: [
async ({request, response}, next) => {
const {method, path} = request
if (method === 'POST') {
if (method === 'POST' || method === 'GET') {
if (path.startsWith('/fail')) {
response.status = 422
// eslint-disable-next-line i18n-text/no-en
Expand Down

0 comments on commit 1d5282c

Please sign in to comment.