BooleanInt props now accepts bools too

This commit is contained in:
4eb0da
2022-09-19 12:58:02 +03:00
parent 5c43113d02
commit bd0d5b3a50
4 changed files with 18 additions and 14 deletions
+11 -11
View File
@@ -3,18 +3,18 @@ import Root from './components/Root.svelte';
const json = {
"templates": {},
"card": {
"type": "div2",
"log_id": "snapshot_test_card",
"states": [
{
"state_id": 0,
"div": {
"type": "text",
"text": "Hello world"
}
"type": "div2",
"log_id": "snapshot_test_card",
"states": [
{
"state_id": 0,
"div": {
"type": "text",
"text": "Hello world"
}
]
}
}
]
}
};
window.root = new Root({
@@ -1,5 +1,5 @@
export function correctBooleanInt(val: number | undefined, defaultVal: boolean): boolean {
if (val === 1 || val === 0) {
export function correctBooleanInt(val: number | boolean | undefined, defaultVal: boolean): boolean {
if (val === 1 || val === 0 || val === false || val === true) {
return Boolean(val);
}
return defaultVal;
@@ -8,6 +8,10 @@ describe('correctBooleanInt', () => {
expect(correctBooleanInt(1, true)).toBe(true);
expect(correctBooleanInt(0, false)).toBe(false);
expect(correctBooleanInt(0, true)).toBe(false);
expect(correctBooleanInt(true, false)).toBe(true);
expect(correctBooleanInt(true, true)).toBe(true);
expect(correctBooleanInt(false, false)).toBe(false);
expect(correctBooleanInt(false, true)).toBe(false);
expect(correctBooleanInt(undefined, false)).toBe(false);
expect(correctBooleanInt(undefined, true)).toBe(true);
});
+1 -1
View File
@@ -1,4 +1,4 @@
export type BooleanInt = 0 | 1;
export type BooleanInt = 0 | 1 | false | true;
export type TemplateContext = Record<string, unknown>;