1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 22:47:44 +00:00

LibJS: Add all of the WeakSet.prototype methods (add, delete, has)

This commit is contained in:
Idan Horowitz 2021-06-09 19:23:28 +03:00 committed by Linus Groh
parent 8b6beac5ce
commit fb63aeae4d
5 changed files with 85 additions and 0 deletions

View file

@ -0,0 +1,16 @@
test("basic functionality", () => {
expect(WeakSet.prototype.add).toHaveLength(1);
const weakSet = new WeakSet([{ a: 1 }, { a: 2 }, { a: 3 }]);
expect(weakSet.add({ a: 4 })).toBe(weakSet);
expect(weakSet.add({ a: 1 })).toBe(weakSet);
});
test("invalid values", () => {
const weakSet = new WeakSet();
[-100, Infinity, NaN, "hello", 152n].forEach(value => {
expect(() => {
weakSet.add(value);
}).toThrowWithMessage(TypeError, "is not an object");
});
});

View file

@ -0,0 +1,9 @@
test("basic functionality", () => {
expect(WeakSet.prototype.delete).toHaveLength(1);
var original = [{ a: 1 }, { a: 2 }, { a: 3 }];
const weakSet = new WeakSet(original);
expect(weakSet.delete(original[0])).toBeTrue();
expect(weakSet.delete(original[0])).toBeFalse();
expect(weakSet.delete(null)).toBeFalse();
});

View file

@ -0,0 +1,12 @@
test("length is 1", () => {
expect(WeakSet.prototype.has).toHaveLength(1);
});
test("basic functionality", () => {
var original = [{ a: 1 }, { a: 2 }, { a: 3 }];
var weakSet = new WeakSet(original);
expect(new WeakSet().has()).toBeFalse();
expect(weakSet.has(original[0])).toBeTrue();
expect(weakSet.has({ a: 1 })).toBeFalse();
});