void-basic.js 1.0 KB

1234567891011121314151617181920212223242526
  1. test("basic functionality", () => {
  2. expect(void "").toBeUndefined();
  3. expect(void "foo").toBeUndefined();
  4. expect(void 1).toBeUndefined();
  5. expect(void 42).toBeUndefined();
  6. expect(void true).toBeUndefined();
  7. expect(void false).toBeUndefined();
  8. expect(void null).toBeUndefined();
  9. expect(void undefined).toBeUndefined();
  10. expect(void function () {}).toBeUndefined();
  11. expect(void (() => {})).toBeUndefined();
  12. expect(void (() => "hello friends")()).toBeUndefined();
  13. expect((() => void "hello friends")()).toBeUndefined();
  14. });
  15. describe("errors", () => {
  16. test("treats yield in generator as non variable", () => {
  17. expect("function f() { void yield; }").toEval();
  18. expect("async function f() { void yield; }").toEval();
  19. expect("function *f() { void yield; }").not.toEval();
  20. expect("async function *f() { void yield; }").not.toEval();
  21. expect("class C { *f() { void yield; } }").not.toEval();
  22. expect("var obj = { async function *f() { void yield; } }").not.toEval();
  23. });
  24. });