htmx/test/attributes/hx-prompt.js
MichaelWest22 24a0106f76
Update testing framework to web-test-runner and improve code coverage (#3273)
* Fix old npm dependencies

* implement web-test-runner tests for headless alongside Mocha browser tests

* Increase test and code coverage

* update to 100% coverage and impove eslint

* Update testing Doco

* revert all htmx changes and updates/disable tests needed

* fix browser mocha test

* Default testing to use playwrite only instead of puppeter

* playwright install fix

* Imporve test summary reporting

* flatten false looks closer to original
2025-04-17 17:55:43 -06:00

38 lines
1.2 KiB
JavaScript

describe('hx-prompt attribute', function() {
beforeEach(function() {
this.server = makeServer()
clearWorkArea()
})
afterEach(function() {
this.server.restore()
clearWorkArea()
})
it('hx-prompt should set request header to prompt response', function() {
this.server.respondWith('GET', '/test', function(xhr) {
should.equal(xhr.requestHeaders['HX-Prompt'], 'foo')
xhr.respond(200, {}, 'Clicked!')
})
var promptSave = window.prompt
window.prompt = function() { return 'foo' }
var btn = make('<button hx-get="/test" hx-prompt="test prompt">Click Me!</a>')
btn.click()
this.server.respond()
window.prompt = promptSave
btn.innerHTML.should.equal('Clicked!')
})
it('hx-prompt that is cancled returns null and blocks the request', function() {
this.server.respondWith('GET', '/test', function(xhr) {
xhr.respond(200, {}, 'Clicked!')
})
var promptSave = window.prompt
window.prompt = function() { return null }
var btn = make('<button hx-get="/test" hx-prompt="test prompt">Click Me!</a>')
btn.click()
this.server.respond()
window.prompt = promptSave
btn.innerHTML.should.equal('Click Me!')
})
})