26 lines
932 B
TypeScript
26 lines
932 B
TypeScript
|
|
import { describe, test, expect } from 'vitest';
|
||
|
|
import { FormButton } from './FormButton';
|
||
|
|
|
||
|
|
const toHtml = (FormButton as any).toHtml;
|
||
|
|
|
||
|
|
describe('FormButton.toHtml', () => {
|
||
|
|
test('normal text renders as-is', () => {
|
||
|
|
const { html } = toHtml({ text: 'Send it' }, '');
|
||
|
|
expect(html).toContain('>Send it<');
|
||
|
|
expect(html).toContain('type="submit"');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('type="submit" is a hardcoded literal, not prop-driven', () => {
|
||
|
|
const { html } = toHtml({ text: 'Submit' }, '');
|
||
|
|
expect(html).toMatch(/<button type="submit"/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('text content is escaped for <, >, &, and " (consistent with escapeHtml)', () => {
|
||
|
|
const { html } = toHtml({ text: '<script>alert(1)</script> & "quoted"' }, '');
|
||
|
|
expect(html).not.toContain('<script>');
|
||
|
|
expect(html).toContain('<script>alert(1)</script>');
|
||
|
|
expect(html).toContain('&');
|
||
|
|
expect(html).toContain('"quoted"');
|
||
|
|
});
|
||
|
|
});
|