strict-mode-errors.js 696 B

12345678910111213141516171819
  1. "use strict";
  2. test("basic functionality", () => {
  3. [true, false, "foo", 123, 123n, null, undefined].forEach(primitive => {
  4. let description = `${typeof primitive} '${primitive}${
  5. typeof primitive == "bigint" ? "n" : ""
  6. }'`;
  7. if (primitive == null) description = String(primitive);
  8. expect(() => {
  9. primitive.foo = "bar";
  10. }).toThrowWithMessage(TypeError, `Cannot set property 'foo' of ${description}`);
  11. expect(() => {
  12. primitive[Symbol.hasInstance] = 123;
  13. }).toThrowWithMessage(
  14. TypeError,
  15. `Cannot set property 'Symbol(Symbol.hasInstance)' of ${description}`
  16. );
  17. });
  18. });