S.data.spec.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. describe("S.data", function () {
  2. it("takes and returns an initial value", function () {
  3. expect(S.data(1)()).toBe(1);
  4. });
  5. it("can be set by passing in a new value", function () {
  6. var d = S.data(1);
  7. d(2);
  8. expect(d()).toBe(2);
  9. });
  10. it("returns value being set", function () {
  11. var d = S.data(1);
  12. expect(d(2)).toBe(2);
  13. });
  14. it("does not throw if set to the same value twice in a freeze", function () {
  15. var d = S.data(1);
  16. S.freeze(() => {
  17. d(2);
  18. d(2);
  19. });
  20. expect(d()).toBe(2);
  21. });
  22. it("throws if set to two different values in a freeze", function () {
  23. var d = S.data(1);
  24. S.freeze(() => {
  25. d(2);
  26. expect(() => d(3)).toThrowError(/conflict/);
  27. });
  28. });
  29. it("does not throw if set to the same value twice in a computation", function () {
  30. S.root(() => {
  31. var d = S.data(1);
  32. S(() => {
  33. d(2);
  34. d(2);
  35. });
  36. expect(d()).toBe(2);
  37. });
  38. });
  39. it("throws if set to two different values in a computation", function () {
  40. S.root(() => {
  41. var d = S.data(1);
  42. S(() => {
  43. d(2);
  44. expect(() => d(3)).toThrowError(/conflict/);
  45. });
  46. });
  47. });
  48. });