From 1d5282c24e290d87e19a87a4dfb317d24fe91952 Mon Sep 17 00:00:00 2001 From: Simon Taranto Date: Tue, 28 May 2024 17:31:13 +0000 Subject: [PATCH] Add specs --- src/auto-check-element.ts | 3 +++ test/auto-check.js | 29 +++++++++++++++++++++++++++++ web-test-runner.config.js | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/auto-check-element.ts b/src/auto-check-element.ts index 9b0ea51..6ee8206 100644 --- a/src/auto-check-element.ts +++ b/src/auto-check-element.ts @@ -219,6 +219,9 @@ function makeAbortController() { } async function fetchWithNetworkEvents(el: Element, url: string, options: RequestInit): Promise { + if (options.method === 'GET') { + delete options.body + } try { const response = await fetch(url, options) el.dispatchEvent(new Event('load')) diff --git a/test/auto-check.js b/test/auto-check.js index 67c12be..611a674 100644 --- a/test/auto-check.js +++ b/test/auto-check.js @@ -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 = ` + + + ` + 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 diff --git a/web-test-runner.config.js b/web-test-runner.config.js index fa0fabd..a68f5cd 100644 --- a/web-test-runner.config.js +++ b/web-test-runner.config.js @@ -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