S.value.spec.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. describe("S.value", function () {
  2. it("takes and returns an initial value", function () {
  3. expect(S.value(1)()).toBe(1);
  4. });
  5. it("can be set by passing in a new value", function () {
  6. var d = S.value(1);
  7. d(2);
  8. expect(d()).toBe(2);
  9. });
  10. it("returns value being set", function () {
  11. var d = S.value(1);
  12. expect(d(2)).toBe(2);
  13. });
  14. it("does not propagate if set to equal value", function () {
  15. S.root(function () {
  16. var d = S.value(1),
  17. e = 0,
  18. f = S(function () { d(); return ++e; });
  19. expect(f()).toBe(1);
  20. d(1);
  21. expect(f()).toBe(1);
  22. });
  23. });
  24. it("propagate if set to unequal value", function () {
  25. S.root(function () {
  26. var d = S.value(1),
  27. e = 0,
  28. f = S(function () { d(); return ++e; });
  29. expect(f()).toBe(1);
  30. d(1);
  31. expect(f()).toBe(1);
  32. d(2);
  33. expect(f()).toBe(2);
  34. });
  35. });
  36. it("can take an equality predicate", function () {
  37. S.root(function () {
  38. var d = S.value([1], function (a, b) { return a[0] === b[0]; }),
  39. e = 0,
  40. f = S(function () { d(); return ++e; });
  41. expect(f()).toBe(1);
  42. d([1]);
  43. expect(f()).toBe(1);
  44. d([2]);
  45. expect(f()).toBe(2);
  46. });
  47. });
  48. });