with-basic.js 508 B

123456789101112131415161718192021222324
  1. test("basic with statement functionality", () => {
  2. var object = { foo: 5, bar: 6, baz: 7 };
  3. var qux = 1;
  4. var bar = 99;
  5. with (object) {
  6. expect(foo).toBe(5);
  7. expect(bar).toBe(6);
  8. expect(baz).toBe(7);
  9. expect(qux).toBe(1);
  10. expect(typeof quz).toBe("undefined");
  11. bar = 2;
  12. }
  13. expect(object.bar).toBe(2);
  14. expect(bar).toBe(99);
  15. });
  16. test("syntax error in strict mode", () => {
  17. expect("'use strict'; with (foo) {}").not.toEval();
  18. });