From ec55a11e80450c162bbb7da1b590f37698250598 Mon Sep 17 00:00:00 2001 From: nprimo Date: Thu, 1 Sep 2022 15:54:08 +0100 Subject: [PATCH] test(declarations): Add new tests to check if variables are constat --- js/tests/declarations_test.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/tests/declarations_test.js b/js/tests/declarations_test.js index 53d1ed9a..26dfc78a 100644 --- a/js/tests/declarations_test.js +++ b/js/tests/declarations_test.js @@ -1,5 +1,13 @@ export const tests = [] const t = (f) => tests.push(f) +const isConst = (name) => { + try { + eval(`${name} = 'm'`) + return false + } catch (err) { + return true + } +} // escapeStr // is declared and of type string @@ -72,4 +80,8 @@ t(() => nested.obj.update === undefined) t(() => cantEdit(() => nested.arr.push('hot stuff'))) t(() => nested.arr.length === 3) +// check if all variable are const +t(() => ['escapeStr', 'arr', 'obj', 'nested'] + .every(isConst)) + Object.freeze(tests)