try-catch-finally-return.js 870 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. test("return from try block", () => {
  2. function foo() {
  3. try {
  4. return "foo";
  5. } catch {
  6. return "bar";
  7. }
  8. }
  9. expect(foo()).toBe("foo");
  10. });
  11. test("return from catch block", () => {
  12. function foo() {
  13. try {
  14. throw "foo";
  15. } catch {
  16. return "bar";
  17. }
  18. }
  19. expect(foo()).toBe("bar");
  20. });
  21. test("return from finally block", () => {
  22. function foo() {
  23. try {
  24. return "foo";
  25. } catch {
  26. return "bar";
  27. } finally {
  28. return "baz";
  29. }
  30. }
  31. expect(foo()).toBe("baz");
  32. });
  33. test("return from catch block with empty finally", () => {
  34. function foo() {
  35. try {
  36. throw "foo";
  37. } catch {
  38. return "bar";
  39. } finally {
  40. }
  41. }
  42. expect(foo()).toBe("bar");
  43. });