Skip to content

Truly independent web browser

1.8 KB
Raw Blame
test("constructor properties", () => {
    expect(String).toHaveLength(1);
    expect(String.name).toBe("String");
});

test("typeof", () => {
    expect(typeof String()).toBe("string");
    expect(typeof new String()).toBe("object");
});

test("length", () => {
    expect(new String().length).toBe(0);
    expect(new String("a").length).toBe(1);
    expect(new String("\u180E").length).toBe(1);
    expect(new String("\uDBFF\uDFFF").length).toBe(2);

    // Issue #2280
    expect("β›³".length).toBe(1);
    expect("πŸ”₯".length).toBe(2);
    expect("πŸ”₯πŸ”₯πŸ”₯".length).toBe(6);
    expect("πŸ‘¨β€πŸ‘©β€πŸ‘¦".length).toBe(8);
    expect("πŸ‘©β€β€οΈβ€πŸ’‹β€πŸ‘©".length).toBe(11);
});

test("indices", () => {
    expect("abc"[0]).toBe("a");
    expect("abc"[1]).toBe("b");
    expect("abc"[2]).toBe("c");
    expect("abc"[3]).toBeUndefined();

    expect("πŸ˜€"[0]).toBe("\ud83d");
    expect("πŸ˜€"[1]).toBe("\ude00");
    expect("πŸ˜€"[2]).toBeUndefined();
});

test("properties", () => {
    expect(Object.getOwnPropertyNames("")).toEqual(["length"]);
    expect(Object.getOwnPropertyNames("a")).toEqual(["0", "length"]);
    expect(Object.getOwnPropertyNames("ab")).toEqual(["0", "1", "length"]);
    expect(Object.getOwnPropertyNames("abc")).toEqual(["0", "1", "2", "length"]);
    expect(Object.getOwnPropertyNames("πŸ˜€")).toEqual(["0", "1", "length"]);
});

test("less than", () => {
    expect("a" < "").toBe(false);
    expect("a" < "b").toBe(true);
    expect("a" < "aa").toBe(true);
    expect("aa" < "a").toBe(false);
    expect("abc" < "abd").toBe(true);
    expect("abc" < "abcd").toBe(true);
    expect("πŸ˜€" < "😁").toBe(true);
    expect("" < "😁").toBe(true);
    expect("😁" < "").toBe(false);
    expect("a" < "A").toBe(false);
    expect("a" < "a").toBe(false);
    expect("~" < "πŸ˜€").toBe(false);
});