Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: adamsanderson/ivy
base: 8a1ecbebed
...
head fork: adamsanderson/ivy
compare: 2fd2d00fdb
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 98 additions and 0 deletions.
  1. +98 −0 test/tests.js
View
98 test/tests.js
@@ -382,4 +382,102 @@ describe('IvyWrap', function(){
assert.equal(wrap.get(), '30%');
});
});
+});
+
+describe('Ivy.fn', function(){
+ function callback(){};
+
+ describe('constructor', function(){
+ it('returns an IvyAttr', function(){
+ var attr = Ivy.fn(callback);
+
+ assert.instanceOf(attr, IvyAttr);
+ });
+
+ it('listens to changes on arguments', function(){
+ var a = Ivy.attr(),
+ b = Ivy.attr(),
+ attr = Ivy.fn(a,b,callback);
+
+ assert.equal(a.callbacks['change'].length, 1);
+ assert.equal(b.callbacks['change'].length, 1);
+ });
+
+ it('calls the function once immediately', function(){
+ var calls = 0,
+ attr = Ivy.fn(function(){ return calls++; });
+
+ assert.equal(calls, 1);
+ });
+ });
+
+ describe('observing', function(){
+ it('updates when its parameters update', function(){
+ var a = Ivy.attr(3),
+ b = Ivy.attr(4),
+ attr = Ivy.fn(a,b, function(alpha, beta){
+ return alpha + beta;
+ });
+
+ b.set(6);
+ assert.equal(attr.get(), 9);
+ });
+
+ it('calls the function arguments in the order they were listed', function(done){
+ var a = Ivy.attr(3),
+ b = Ivy.attr(4);
+
+ Ivy.fn(a,b, function(alpha, beta){
+ assert.equal(alpha, a);
+ assert.equal(beta, b);
+ done();
+ });
+ });
+
+ it('emits an event when its value changes', function(done){
+ var a = Ivy.attr(3),
+ attr = Ivy.fn(a, function(alpha){
+ return alpha + 1;
+ });
+
+ attr.on('change',function(value){
+ assert.equal(value, 5);
+ done();
+ });
+
+ a.set(4);
+ });
+ });
+
+ describe('#get', function(){
+ it('returns the computed value', function(){
+ var attr = Ivy.fn(function(){
+ return 7;
+ });
+
+ assert.equal(attr.get(), 7);
+ });
+ });
+});
+
+describe('Ivy.fnWith', function(){
+ function callback(){};
+
+ describe('constructor', function(){
+ it('returns an IvyAttr', function(){
+ var attr = Ivy.fnWith({}, callback);
+
+ assert.instanceOf(attr, IvyAttr);
+ });
+
+ it('listens to changes on arguments', function(){
+ var a = Ivy.attr(),
+ b = Ivy.attr(),
+ obj = {alpha: a, beta: b},
+ attr = Ivy.fnWith(obj,function(alpha, beta){});
+
+ assert.equal(a.callbacks['change'].length, 1);
+ assert.equal(b.callbacks['change'].length, 1);
+ });
+ });
});

No commit comments for this range

Something went wrong with that request. Please try again.