ternary-basic.js 524 B

1234567891011121314151617181920
  1. test("basic functionality", () => {
  2. const x = 1;
  3. expect(x === 1 ? true : false).toBeTrue();
  4. expect(x ? x : 0).toBe(x);
  5. expect(1 < 2 ? true : false).toBeTrue();
  6. expect(0 ? 1 : 1 ? 10 : 20).toBe(10);
  7. expect(0 ? (1 ? 1 : 10) : 20).toBe(20);
  8. });
  9. test("object values", () => {
  10. const o = {};
  11. o.f = true;
  12. expect(o.f ? true : false).toBeTrue();
  13. expect(1 ? o.f : null).toBeTrue();
  14. });
  15. test("issue #4409, '?.' followed by decimal digit", () => {
  16. expect("false?.1:.2").toEvalTo(0.2);
  17. });