strict-mode-errors.js 842 B

1234567891011121314151617181920212223
  1. "use strict";
  2. test("basic functionality", () => {
  3. [true, false, "foo", 123].forEach(primitive => {
  4. expect(() => {
  5. primitive.foo = "bar";
  6. }).toThrowWithMessage(TypeError, `Cannot set property 'foo' of ${primitive}`);
  7. expect(() => {
  8. primitive[Symbol.hasInstance] = 123;
  9. }).toThrowWithMessage(
  10. TypeError,
  11. `Cannot set property 'Symbol(Symbol.hasInstance)' of ${primitive}`
  12. );
  13. });
  14. [null, undefined].forEach(primitive => {
  15. expect(() => {
  16. primitive.foo = "bar";
  17. }).toThrowWithMessage(TypeError, `${primitive} cannot be converted to an object`);
  18. expect(() => {
  19. primitive[Symbol.hasInstance] = 123;
  20. }).toThrowWithMessage(TypeError, `${primitive} cannot be converted to an object`);
  21. });
  22. });