throw-basic.js 668 B

12345678910111213141516171819202122232425262728293031323334
  1. test("throw literal", () => {
  2. try {
  3. throw 1;
  4. expect().fail();
  5. } catch (e) {
  6. if (e.name === "ExpectationError") throw e;
  7. expect(e).toBe(1);
  8. }
  9. });
  10. test("throw array", () => {
  11. try {
  12. throw [99];
  13. expect().fail();
  14. } catch (e) {
  15. if (e.name === "ExpectationError") throw e;
  16. expect(e).toEqual([99]);
  17. }
  18. });
  19. test("call function that throws", () => {
  20. function foo() {
  21. throw "hello";
  22. expect().fail();
  23. }
  24. try {
  25. foo();
  26. expect().fail();
  27. } catch (e) {
  28. if (e.name === "ExpectationError") throw e;
  29. expect(e).toBe("hello");
  30. }
  31. });