Skip to content

Commit d58698d

Browse files
committed
Add a test
1 parent c13c107 commit d58698d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"coveralls": "^3.0.9",
3333
"eslint-config-xo-overrides": "^1.4.0",
3434
"husky": "^7.0.4",
35+
"mem": "^8",
3536
"nyc": "^15.0.0",
3637
"xo": "^0.47.0"
3738
},

src/index.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import v8 from 'v8';
55
import type { ExecutionContext, Macro } from 'ava';
66
import test from 'ava';
77

8+
import mem from 'mem';
89
import DeepWeakMap from '.';
910

1011
const iterations = 2 ** 21;
@@ -182,3 +183,26 @@ test.serial('DeepWeakMap types', t => {
182183
name: 'TypeError',
183184
});
184185
});
186+
187+
test.serial('Integration with mem', t => {
188+
type A = { a: number };
189+
type B = { b: number };
190+
191+
type Value = { value: number };
192+
193+
let callCount = 0;
194+
const f = mem((a: A, b: B): Value => ({
195+
value: a.a + b.b + callCount++,
196+
}), {
197+
cacheKey: arguments_ => arguments_,
198+
cache: new DeepWeakMap(),
199+
});
200+
201+
const a0 = { a: 0 };
202+
const b0 = { b: 0 };
203+
204+
t.is(f(a0, b0).value, 0);
205+
t.is(f(a0, b0).value, 0);
206+
207+
t.is(callCount, 1);
208+
});

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2905,7 +2905,7 @@ md5-hex@^3.0.1:
29052905
dependencies:
29062906
blueimp-md5 "^2.10.0"
29072907

2908-
mem@^8.0.0:
2908+
mem@^8, mem@^8.0.0:
29092909
version "8.1.1"
29102910
resolved "https://registry.yarnpkg.com/mem/-/mem-8.1.1.tgz#cf118b357c65ab7b7e0817bdf00c8062297c0122"
29112911
integrity sha512-qFCFUDs7U3b8mBDPyz5EToEKoAkgCzqquIgi9nkkR9bixxOVOre+09lbuH7+9Kn2NFpm56M3GUWVbU2hQgdACA==

0 commit comments

Comments
 (0)