Skip to content

Commit b957d4c

Browse files
committed
fix: toString method can now handle 0 as number
1 parent 589f776 commit b957d4c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/comparators.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ export abstract class Comparator implements Item {
77
constructor(protected selector: Function | string, protected comparatorKeyWord: string, protected value?: string | number) {}
88

99
toString(): string {
10-
if (this.value) {
11-
if (typeof this.value === 'number') {
12-
return `${this.selector} ${this.comparatorKeyWord} ${this.value}`;
13-
} else {
14-
return `${this.selector} ${this.comparatorKeyWord} '${this.value}'`;
15-
}
10+
if (typeof this.value === 'undefined' || this.value === null) return `${this.selector} ${this.comparatorKeyWord}`;
11+
if (typeof this.value === 'number') {
12+
return `${this.selector} ${this.comparatorKeyWord} ${this.value}`;
13+
} else {
14+
return `${this.selector} ${this.comparatorKeyWord} '${this.value}'`;
1615
}
17-
return `${this.selector} ${this.comparatorKeyWord}`;
1816
}
1917
}
2018

test/comparators.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,7 @@ test('not in string[]', () => {
9595
test('not in number[]', () => {
9696
expect(sfNotIn('status', [1, 2]).toString()).toBe('status not in [1, 2]');
9797
});
98+
99+
test('.toString() can handle 0 as number', () => {
100+
expect(sfEqual('id', 0).toString()).toBe('id : 0');
101+
});

0 commit comments

Comments
 (0)