module('Ember.isWatching');

var testObserver = function(setup, teardown) {
  var obj = {}, key = 'foo', fn = function() {};

  equal(Ember.isWatching(obj, 'foo'), false, "precond - isWatching is false by default");
  setup(obj, key, fn);
  equal(Ember.isWatching(obj, 'foo'), true, "isWatching is true when observers are added");
  teardown(obj, key, fn);
  equal(Ember.isWatching(obj, 'foo'), false, "isWatching is false after observers are removed");
};

test("isWatching is true for regular local observers", function() {
  testObserver(function(obj, key, fn) {
    Ember.Mixin.create({
      didChange: Ember.observer(fn, key)
    }).apply(obj);
  }, function(obj, key, fn) {
    Ember.removeObserver(obj, key, obj, fn);
  });
});

test("isWatching is true for nonlocal observers", function() {
  testObserver(function(obj, key, fn) {
    Ember.addObserver(obj, key, obj, fn);
  }, function(obj, key, fn) {
    Ember.removeObserver(obj, key, obj, fn);
  });
});

test("isWatching is true for chained observers", function() {
  testObserver(function(obj, key, fn) {
    Ember.addObserver(obj, key + '.bar', obj, fn);
  }, function(obj, key, fn) {
    Ember.removeObserver(obj, key + '.bar', obj, fn);
  });
});

test("isWatching is true for computed properties", function() {
  testObserver(function(obj, key, fn) {
    Ember.defineProperty(obj, 'computed', Ember.computed(fn).property(key));
    Ember.watch(obj, 'computed');
  }, function(obj, key, fn) {
    Ember.defineProperty(obj, 'computed', null);
  });
});

test("isWatching is true for chained computed properties", function() {
  testObserver(function(obj, key, fn) {
    Ember.defineProperty(obj, 'computed', Ember.computed(fn).property(key + '.bar'));
    Ember.watch(obj, 'computed');
  }, function(obj, key, fn) {
    Ember.defineProperty(obj, 'computed', null);
  });
});

@@ -65,16 +65,21 @@
 teardown
+, key
 ) %7B%0A  va
@@ -93,21 +93,8 @@
  %7B%7D,
- key = 'foo',
  fn 
@@ -109,16 +109,38 @@
 on() %7B%7D;
+%0A  key = key %7C%7C 'foo';
 %0A%0A  equa
@@ -155,37 +155,35 @@
 isWatching(obj, 
-'foo'
+key
 ), false, %22preco
@@ -274,21 +274,19 @@
 ng(obj, 
-'foo'
+key
 ), true,
@@ -390,21 +390,19 @@
 ng(obj, 
-'foo'
+key
 ), false
@@ -1823,28 +1823,465 @@
 computed', null);%0A  %7D);%0A%7D);%0A
+%0A// can't watch length on Array - it is special...%0A// But you should be able to watch a length property of an object%0Atest(%22isWatching is true for 'length' property on object%22, function() %7B%0A  testObserver(function(obj, key, fn) %7B%0A    Ember.defineProperty(obj, 'length', null, '26.2 miles');%0A    Ember.addObserver(obj, 'length', obj, fn);%0A  %7D, function(obj, key, fn) %7B%0A    Ember.removeObserver(obj, 'length', obj, fn);%0A  %7D, 'length');%0A%7D);%0A

Test for isWatching on length property of an object