custom-@@toStringTag.js 556 B

1234567891011121314151617181920212223242526
  1. test("inside objects", () => {
  2. const o = {
  3. [Symbol.toStringTag]: "hello friends",
  4. };
  5. expect(o.toString()).toBe("[object hello friends]");
  6. });
  7. test("inside classes", () => {
  8. class A {
  9. constructor() {
  10. this[Symbol.toStringTag] = "hello friends";
  11. }
  12. }
  13. const a = new A();
  14. expect(a.toString()).toBe("[object hello friends]");
  15. });
  16. test("non-string values are ignored", () => {
  17. const o = {
  18. [Symbol.toStringTag]: [1, 2, 3],
  19. };
  20. expect(o.toString()).toBe("[object Object]");
  21. });