Lifecycle / Testing helpers
@inputcn/testing
Driving a masked field from a test is its own small nightmare. This package does it for you, the way a user would.
Fill, leave, assert
import { fillCurrency, leaveField, expectInvalid, expectFormData } from "@inputcn/testing"
it("rejects a budget over the cap", async () => {
const { field } = renderField(<CurrencyInput label="Budget" max={100000} />)
await fillCurrency(field, 250000)
await leaveField(field)
// Asserts the RULE, not the sentence. Rewording the copy does not break this.
expectInvalid(field, "max")
})What is in it
HELPERKINDDOES
fillPhone, fillCurrency, …11 helpersTypes a canonical value into the field, keystroke by keystroke
pasteIntoactionPastes text and runs the component paste handler
leaveFieldactionFocuses the field if needed, then blurs it — so validation actually runs
expectValueassertionCompares against the canonical value, naming both on failure
expectInvalid(field, rule)assertionAsserts which rule failed, by data-rule
expectFormDataassertionChecks what a real submit would send
renderField / renderInForm / renderManagedrenderThe three modes a field can be used in
A bug this package found in itself
leaveField originally assumed focus was already inside the field. Called on an untouched field it fired no blur at all, so validation silently never ran — which reads as “the component is broken”. It focuses first now.