mirror of https://github.com/lukechilds/ow.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.7 KiB
31 lines
1.7 KiB
7 years ago
|
import test from 'ava';
|
||
|
import m from '..';
|
||
|
|
||
|
test('weakMap', t => {
|
||
|
t.notThrows(() => m(new WeakMap(), m.weakMap));
|
||
|
t.notThrows(() => m(new WeakMap([[{foo: 'bar'}, '🦄']]), m.weakMap));
|
||
|
t.throws(() => m(12 as any, m.weakMap), 'Expected argument to be of type `weakMap` but received type `number`');
|
||
|
});
|
||
|
|
||
|
test('weakMap.hasKeys', t => {
|
||
|
const unicorn: any = {unicorn: true};
|
||
|
const rainbow: any = {rainbow: true};
|
||
|
const keys = [{x: 1}, {x: 2}, {x: 3}, {x: 4}, {x: 5}, {x: 6}, {x: 7}, {x: 8}, {x: 9}, {x: 10}];
|
||
|
|
||
|
t.notThrows(() => m(new WeakMap([[unicorn, '🦄']]), m.weakMap.hasKeys(unicorn)));
|
||
|
t.throws(() => m(new WeakMap([[{rainbow: true}, '🌈']]), m.weakMap.hasKeys({rainbow: true})), 'Expected WeakMap to have keys `[{"rainbow":true}]`');
|
||
|
t.throws(() => m(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), m.weakMap.hasKeys(unicorn, {rainbow: true})), 'Expected WeakMap to have keys `[{"rainbow":true}]`');
|
||
|
t.throws(() => m(new WeakMap([[keys[0], 1], [keys[2], 3]]), m.weakMap.hasKeys(...keys)), 'Expected WeakMap to have keys `[{"x":2},{"x":4},{"x":5},{"x":6},{"x":7}]`');
|
||
|
});
|
||
|
|
||
|
test('weakMap.hasAnyKeys', t => {
|
||
|
const unicorn: any = {unicorn: true};
|
||
|
const rainbow: any = {rainbow: true};
|
||
|
const rocket: any = {rocket: true};
|
||
|
|
||
|
t.notThrows(() => m(new WeakMap([[unicorn, '🦄']]), m.weakMap.hasAnyKeys(unicorn, rainbow)));
|
||
|
t.notThrows(() => m(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), m.weakMap.hasAnyKeys(unicorn)));
|
||
|
t.notThrows(() => m(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), m.weakMap.hasAnyKeys(unicorn, rainbow, rocket)));
|
||
|
t.throws(() => m(new WeakMap([[unicorn, '🦄'], [rainbow, '🌈']]), m.weakMap.hasAnyKeys(rocket)), 'Expected WeakMap to have any key of `[{"rocket":true}]`');
|
||
|
});
|