Skip to content

Commit

Permalink
refactor: tidy up IsNull and extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meenahoda authored and Meena Brend committed Sep 15, 2022
1 parent b2ef9da commit f5efe84
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 6 additions & 6 deletions lib/operators/is-null.js
Original file line number Diff line number Diff line change
@@ -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
}
}
9 changes: 8 additions & 1 deletion test/data-test-expr-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down

0 comments on commit f5efe84

Please sign in to comment.