Javascript BDD

It was a long time since I delved into Scriptaculous subversion repository. This morning I was browsing it to find out what’s coming for next versions (seems 2.0 is not so far away) and had a good surprise : it seems they add BDD to their test framework.

I must admit my last try to use TDD for my Javascripts do not last long and this is a great reason to try again but this time BDD-Style.

To give you a little overview of what it looks like here’s a snippet extracted from the specs for the BDD framework itself :

Test.context("BDD-style testing",{
  
  setup: function() {
    ...
  },
  
  teardown: function() {
    ...
  },
  
  'should provide extensions to tie in isSomething and respondsTo object methods': function(){
    ...

    testObj.shouldBe('nice');
    testObj.shouldNotBe('broken');
    
    testObj.shouldRespondTo('isNice');
    testObj.shouldRespondTo('isBroken');
  },
  
  'should automatically add extensions to strings': function(){
    'a'.shouldEqual('a');
    'a'.shouldNotEqual('b');
    'a'.shouldNotBeNull();
    'a'.shouldBeA(String);
  }
}

If you’re using RSpec it should (woot!) looks familiar.

Sun, 07 Oct 2007 13:57 Posted in ,

  1. By TJ Holowaychuk 06/04/2009 at 21h03


  2. By Jonathan Tron 07/04/2009 at 11h05


    Indeed it looks great, event if I’m not convince that the syntax is not written in valid Javascript.

    It looks like RSpec, it feels like RSpec, but RSpec does one thing which is great, it’s all valid ruby.
    Other javascript BDD libraries out there can certainly not compete with your clean syntax, but they keep tests as valid javascript.

    Good work anyway, I really like the matchers and the report template.

  3. By Tj Holowaychuk 22/05/2009 at 05h00


    Certainly, the grammar is optionally though as of 2.0. So users may go ahead and use literal JavaScript if they like.

Comment Javascript BDD


RSS