');
let button = find('button');
button.click();
await forRequest();
assert.equal(find('#target').textContent, 'Server Error');
});
it('can change target based on status', async function() {
createProcessedHTML('');
mockResponse('GET', '/test', 'Not Found', {status: 404});
let button = find('button');
button.click();
await forRequest();
assert.equal(find('#error').innerText, 'Not Found');
assert.equal(find('#success').innerText, '');
});
it('can select different content based on status', async function() {
mockResponse('GET', '/test', '
Success!
Failed!
', {status: 422});
createProcessedHTML('');
let button = find('button');
button.click();
await forRequest();
assert.include(find('#target').innerText, 'Failed!');
assert.notInclude(find('#target').innerText, 'Success!');
});
it('can set multiple properties with hx-status', async function() {
createProcessedHTML('');
mockResponse('GET', '/test', '
Invalid input
', {status: 422});
let button = find('button');
button.click();
await forRequest();
assert.equal(find('#errors').textContent, 'Invalid input');
assert.equal(find('#main').textContent, '');
});
it('prefers exact match over wildcard', async function() {
mockResponse('GET', '/test', '
Specific
', {status: 404});
createProcessedHTML('');
// Since we're not including those IDs in response, this tests that 404 is matched first
let button = find('button');
button.click();
await forRequest();
// The test verifies the order of evaluation
});
it('can prevent history update on error', async function() {
mockResponse('GET', '/test', '
Error
', {status: 500});
createProcessedHTML('');
let originalUrl = window.location.href;
let button = find('button');
button.click();
await forRequest();
assert.equal(window.location.href, originalUrl);
});
it('works with 2-digit wildcard pattern', async function() {
mockResponse('GET', '/test', '
Server Error
', {status: 503});
createProcessedHTML('');
let button = find('button');
button.click();
await forRequest();
assert.equal(find('#target').textContent, 'Server Error');
});
it('does not apply when status does not match', async function() {
mockResponse('GET', '/test', '
Success
', {status: 200});
createProcessedHTML('
Original
');
let button = find('button');
button.click();
await forRequest();
assert.equal(find('#target').textContent, 'Success');
});
it('can set swap to none on error', async function() {
mockResponse('GET', '/test', '