Skip to content

Commit

Permalink
refactor: tidy up IsUndefined and extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
meenahoda committed Sep 15, 2022
1 parent f5efe84 commit 00dea40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
18 changes: 8 additions & 10 deletions lib/operators/is-undefined.js
@@ -1,15 +1,13 @@
'use strict'

module.exports = function isUndefinedOperator (inputValue, comparisonValue, candidateStateName, cache) {
let nextState
if (comparisonValue === true) {
if (inputValue === undefined) {
nextState = candidateStateName
}
} else if (comparisonValue === false) {
if (inputValue !== undefined) {
nextState = candidateStateName
}
const isUndefined = inputValue === undefined

if (isUndefined && comparisonValue === true) {
return candidateStateName
}

if (!isUndefined && comparisonValue !== true) {
return candidateStateName
}
return nextState
}
13 changes: 13 additions & 0 deletions test/data-test-expr-tests.js
Expand Up @@ -77,6 +77,19 @@ const tests = {
[0, true, 'DefaultState'],
[false, true, 'DefaultState']
],
IsUndefined: [
[undefined, true, 'NextState'],
['HELLO_WORLD', false, 'NextState'],
[null, false, 'NextState'],
[0, false, 'NextState'],
[false, false, 'NextState'],

[undefined, false, 'DefaultState'],
['HELLO_WORLD', true, 'DefaultState'],
[null, true, 'DefaultState'],
[0, true, 'DefaultState'],
[false, true, 'DefaultState']
],
IsBoolean: [
['nope', false, 'NextState'],
[true, true, 'NextState'],
Expand Down

0 comments on commit 00dea40

Please sign in to comment.