From f5efe84d1590c6d47dede3faeaa366c5012fbd0f Mon Sep 17 00:00:00 2001 From: meenahoda Date: Thu, 15 Sep 2022 10:36:48 +0100 Subject: [PATCH] refactor: tidy up IsNull and extend tests --- lib/operators/is-null.js | 12 ++++++------ test/data-test-expr-tests.js | 9 ++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/operators/is-null.js b/lib/operators/is-null.js index ee43e33..3e52817 100644 --- a/lib/operators/is-null.js +++ b/lib/operators/is-null.js @@ -1,13 +1,13 @@ 'use strict' module.exports = function isNullOperator (inputValue, comparisonValue, candidateStateName, cache) { - let nextState + const isNull = inputValue === null - if (comparisonValue && inputValue === null) { - nextState = candidateStateName - } else if (!comparisonValue && inputValue !== null) { - nextState = candidateStateName + if (isNull && comparisonValue === true) { + return candidateStateName } - return nextState + if (!isNull && comparisonValue !== true) { + return candidateStateName + } } diff --git a/test/data-test-expr-tests.js b/test/data-test-expr-tests.js index 15a5058..6469cb7 100644 --- a/test/data-test-expr-tests.js +++ b/test/data-test-expr-tests.js @@ -67,14 +67,21 @@ const tests = { IsNull: [ [null, true, 'NextState'], ['HELLO_WORLD', false, 'NextState'], + [undefined, false, 'NextState'], + [0, false, 'NextState'], + [false, false, 'NextState'], [null, false, 'DefaultState'], - ['HELLO_WORLD', true, 'DefaultState'] + ['HELLO_WORLD', true, 'DefaultState'], + [undefined, true, 'DefaultState'], + [0, true, 'DefaultState'], + [false, true, 'DefaultState'] ], IsBoolean: [ ['nope', false, 'NextState'], [true, true, 'NextState'], [false, true, 'NextState'], + ['nope', true, 'DefaultState'], [true, false, 'DefaultState'], [false, false, 'DefaultState']