Files
SnowLuma/packages/webui/tests/otp-input.test.tsx
T
TanTan fa9c73363d
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
SnowLuma v2.4.2 source snapshot
2026-11-13 09:02:00 +08:00

32 lines
1.3 KiB
TypeScript

import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it } from 'vitest';
import { OtpInput } from '../src/components/interior/otp-input';
describe('OtpInput official error/hint contract', () => {
it('shows the hint while error is false', () => {
const markup = renderToStaticMarkup(
<OtpInput
label="验证码"
hint="可以把完整验证码粘贴到任意一格。"
error={false}
errorMessage="验证码不正确,改错的那一位即可。"
/>,
);
expect(markup).toContain('可以把完整验证码粘贴到任意一格。');
expect(markup).not.toContain('验证码不正确,改错的那一位即可。');
});
it('swaps to the error message when error is true', () => {
const markup = renderToStaticMarkup(
<OtpInput
label="验证码"
hint="可以把完整验证码粘贴到任意一格。"
error
errorMessage="验证码不正确,改错的那一位即可。"
/>,
);
expect(markup).toContain('验证码不正确,改错的那一位即可。');
expect(markup).toContain('aria-invalid="true"');
});
});