Skip to content

Commit 89d8a7b

Browse files
fix: $eq condition where first value is null or undefined should always return false (#32)
* Add VSCode settings for a working test explorer sidebar * fix: $eq should return false when any element is null or undefined
1 parent 23fb362 commit 89d8a7b

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

.vscode/extensions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"recommendations": [
3+
"hbenl.vscode-mocha-test-adapter",
4+
"esbenp.prettier-vscode"
5+
]
6+
}

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"npm.packageManager": "yarn",
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"[typescript]": {
5+
"editor.defaultFormatter": "esbenp.prettier-vscode"
6+
},
7+
"mochaExplorer.files": ["tests/**/*.{js,ts,cjs,mjs}"],
8+
"mochaExplorer.require": [
9+
"esbuild-register"
10+
]
11+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ function realTest<Variables>(
106106

107107
const res = testWithPath(input.$eq[0], variables, options, "$eq[0]")
108108

109+
if (res == null) return false
110+
109111
return (
110112
// we test for each element because we need to make sure that the value is fixed if it's a variable
111113
input.$eq.every(

tests/eq.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,32 @@ const data = {
7575
},
7676
{},
7777
],
78+
UndefinedCheck1: [
79+
{
80+
$eq: ["$Value.a"],
81+
},
82+
{
83+
Value: {},
84+
},
85+
],
86+
UndefinedCheck2: [
87+
{
88+
$eq: ["$Value.a", "$Value.a"],
89+
},
90+
{
91+
Value: {},
92+
},
93+
],
94+
NullCheck2: [
95+
{
96+
$eq: ["$Value.a", "$Value.a"],
97+
},
98+
{
99+
Value: {
100+
a: null,
101+
},
102+
},
103+
],
78104
}
79105

80106
describe("$eq", () => {
@@ -116,4 +142,21 @@ describe("$eq", () => {
116142
const [sm, vars] = data.LongArray1
117143
assert.strictEqual(test(sm, vars), true)
118144
})
145+
146+
context("$eq with undefined or null variables", () => {
147+
it("1 (one) undefined variable", () => {
148+
const [sm, vars] = data.UndefinedCheck1
149+
assert.strictEqual(test(sm, vars), false)
150+
})
151+
152+
it("2 undefined variables", () => {
153+
const [sm, vars] = data.UndefinedCheck2
154+
assert.strictEqual(test(sm, vars), false)
155+
})
156+
157+
it("2 null variables", () => {
158+
const [sm, vars] = data.NullCheck2
159+
assert.strictEqual(test(sm, vars), false)
160+
})
161+
})
119162
})

0 commit comments

Comments
 (0)