links for 2011-02-26

February 27, 2011

Advertisements

links for 2011-02-25

February 26, 2011

links for 2011-02-16

February 17, 2011

I came across a small problem with unit testing functions which take a callback. If you write your test like this:

"should callback with error on connection failed": function () {
  thing.doSomething(function(result) {
    Y.Assert.areEqual(result, "error");
  });
},

That test will pass even when the callback is never called. Your code could silently swallow errors, but your test would always pass. The assert never gets called.

If you write the test like this instead:

"should callback with error on connection failed": function () {
  var result;
  thing.doSomething(function(res) {
    result = res;
  });
  Y.Assert.areEqual(result, "error");
},

This will mean that your assert will always get called. You may run into problems if the doSomething function calls something asynchronous – but that’s where dependency injection and mocking can help you.

links for 2011-02-09

February 10, 2011

links for 2011-02-02

February 3, 2011