mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
BooleanInt props now accepts bools too
This commit is contained in:
@@ -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
@@ -1,4 +1,4 @@
|
||||
export type BooleanInt = 0 | 1;
|
||||
export type BooleanInt = 0 | 1 | false | true;
|
||||
|
||||
export type TemplateContext = Record<string, unknown>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user