Page MenuHomeSealhub

boolean.test.ts
No OneTemporary

boolean.test.ts

import assert from "assert";
import { Fields } from "../../index.js";
describe("boolean field", () => {
const ctx = {} as any;
it("validation logic", async () => {
const required = new Fields.Boolean(true);
const not_required = new Fields.Boolean(false);
assert.strictEqual((await required.isValueValid(ctx, true)).valid, true);
assert.strictEqual((await required.isValueValid(ctx, false)).valid, false);
assert.strictEqual((await not_required.isValueValid(ctx, true)).valid, true);
assert.strictEqual((await not_required.isValueValid(ctx, false)).valid, true);
});
it("parse function", async () => {
const field = new Fields.Boolean(true);
const true_response = await field.parse(ctx, true as any);
const null_response = await field.parse(ctx, null as any);
const true_as_string_response = await field.parse(ctx, "true");
const undefined_response = await field.parse(ctx, undefined);
const number_response = await field.parse(ctx, 42);
assert.strictEqual(true_response.parsable, true);
assert.strictEqual(true_response.parsed_value, true);
assert.strictEqual(null_response.parsable, true);
assert.strictEqual(null_response.parsed_value, false);
assert.strictEqual(true_as_string_response.parsable, true);
assert.strictEqual(true_as_string_response.parsed_value, true);
assert.strictEqual(undefined_response.parsable, true);
assert.strictEqual(undefined_response.parsed_value, false);
assert.strictEqual(number_response.parsable, false);
assert.strictEqual(number_response.error, "Please enter a boolean");
});
});

File Metadata

Mime Type
text/x-java
Expires
Tue, Dec 24, 14:02 (20 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
557108
Default Alt Text
boolean.test.ts (1 KB)

Event Timeline