Skip to content

Commit 49b4940

Browse files
committed
test: add onEvict validation tests for non-function callbacks
1 parent 5aa9087 commit 49b4940

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

coverage.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
ℹ file | line % | branch % | funcs % | uncovered lines
44
ℹ ----------------------------------------------------------
55
ℹ src | | | |
6-
ℹ lru.js | 99.70 | 98.54 | 100.00 | 534-535
6+
ℹ lru.js | 100.00 | 99.28 | 100.00 |
77
ℹ ----------------------------------------------------------
8-
ℹ all files | 99.70 | 98.54 | 100.00 |
8+
ℹ all files | 100.00 | 99.28 | 100.00 |
99
ℹ ----------------------------------------------------------
1010
ℹ end of coverage report

tests/unit/lru.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,17 @@ describe("LRU Cache", function () {
12921292
assert.equal(evictedItems[1].key, "b");
12931293
assert.equal(evictedItems[2].key, "c");
12941294
});
1295+
1296+
it("should throw TypeError if callback is not a function", function () {
1297+
assert.throws(() => cache.onEvict(undefined), {
1298+
message: "onEvict callback must be a function",
1299+
});
1300+
assert.throws(() => cache.onEvict(null), { message: "onEvict callback must be a function" });
1301+
assert.throws(() => cache.onEvict("not a function"), {
1302+
message: "onEvict callback must be a function",
1303+
});
1304+
assert.throws(() => cache.onEvict({}), { message: "onEvict callback must be a function" });
1305+
});
12951306
});
12961307

12971308
describe("sizeByTTL method", function () {

0 commit comments

Comments
 (0)