strict-mode-errors.js 920 B

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