From 2f4900d8d20fb65bc1033f0c0be0239f1170bcad Mon Sep 17 00:00:00 2001 From: nprimo Date: Thu, 1 Sep 2022 15:54:39 +0100 Subject: [PATCH] test(primitives): Add new tests to check if variables are constant --- js/tests/primitives_test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/js/tests/primitives_test.js b/js/tests/primitives_test.js index 28dbf02b6..4a4dd9ed9 100644 --- a/js/tests/primitives_test.js +++ b/js/tests/primitives_test.js @@ -1,5 +1,14 @@ export const tests = [] +const isConst = (name) => { + try { + eval(`${name} = 'm'`) + return false + } catch (err) { + return true + } +} const t = (f) => tests.push(f) + // str is declared and of type string t(() => typeof str === 'string') @@ -12,4 +21,8 @@ t(() => typeof bool === 'boolean') // undef is declared and of type undefined t(() => undef === undefined) +// check if all variables are const +t(() => ['str', 'num', 'bool', 'undef'] + .every(isConst)) + Object.freeze(tests)