Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
futpib committed Dec 26, 2021
1 parent c13c107 commit d58698d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"coveralls": "^3.0.9",
"eslint-config-xo-overrides": "^1.4.0",
"husky": "^7.0.4",
"mem": "^8",
"nyc": "^15.0.0",
"xo": "^0.47.0"
},
Expand Down
24 changes: 24 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import v8 from 'v8';
import type { ExecutionContext, Macro } from 'ava';
import test from 'ava';

import mem from 'mem';
import DeepWeakMap from '.';

const iterations = 2 ** 21;
Expand Down Expand Up @@ -182,3 +183,26 @@ test.serial('DeepWeakMap types', t => {
name: 'TypeError',
});
});

test.serial('Integration with mem', t => {
type A = { a: number };
type B = { b: number };

type Value = { value: number };

let callCount = 0;
const f = mem((a: A, b: B): Value => ({
value: a.a + b.b + callCount++,
}), {
cacheKey: arguments_ => arguments_,
cache: new DeepWeakMap(),
});

const a0 = { a: 0 };
const b0 = { b: 0 };

t.is(f(a0, b0).value, 0);
t.is(f(a0, b0).value, 0);

t.is(callCount, 1);
});
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2905,7 +2905,7 @@ md5-hex@^3.0.1:
dependencies:
blueimp-md5 "^2.10.0"

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

0 comments on commit d58698d

Please sign in to comment.