S.exceptions.spec.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. describe("exceptions within S computations", function () {
  2. it("halt updating", function () {
  3. S.root(function () {
  4. var a = S.data(false),
  5. b = S.data(1),
  6. c = S(() => { if (a()) throw new Error("xxx"); }),
  7. d = S(() => b());
  8. expect(() => S.freeze(() => {
  9. a(true);
  10. b(2);
  11. })).toThrowError(/xxx/);
  12. expect(b()).toBe(2);
  13. expect(d()).toBe(1);
  14. });
  15. });
  16. it("do not leave stale scheduled updates", function () {
  17. S.root(function () {
  18. var a = S.data(false),
  19. b = S.data(1),
  20. c = S(() => { if (a()) throw new Error("xxx"); }),
  21. d = S(() => b());
  22. expect(() => S.freeze(() => {
  23. a(true);
  24. b(2);
  25. })).toThrowError(/xxx/);
  26. expect(d()).toBe(1);
  27. // updating a() should not trigger previously scheduled updated of b(), since htat propagation excepted
  28. a(false);
  29. expect(d()).toBe(1);
  30. });
  31. });
  32. it("leave non-excepted parts of dependency tree intact", function () {
  33. S.root(function () {
  34. var a = S.data(false),
  35. b = S.data(1),
  36. c = S(() => { if (a()) throw new Error("xxx"); }),
  37. d = S(() => b());
  38. expect(() => S.freeze(() => {
  39. a(true);
  40. b(2);
  41. })).toThrowError(/xxx/);
  42. expect(b()).toBe(2);
  43. expect(d()).toBe(1);
  44. b(3);
  45. expect(b()).toBe(3);
  46. expect(d()).toBe(3);
  47. });
  48. });
  49. });