Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Created April 30, 2012 17:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilmoore/2560262 to your computer and use it in GitHub Desktop.
Save wilmoore/2560262 to your computer and use it in GitHub Desktop.
YUI Resources for TDD/BDD w/ YUI3 Test

YUI3 Test Limitations

  • YUI3 Test does not support Data Providers for Parameterized Testing. You are welcome to use the extremely hacky solution that I came up with.
  • Because checking for failures (errors/exceptions) must be defined as a separate hash by name, you end up with a lot of duplication and potential for errors if you forget to rename the item in the "error" hash after renaming the test method.
  • Because checking for failures (errors/exceptions) must be defined as a separate hash by name, you lose the ability to dynamically check for errors/exceptions.

Parameterized Testing Hack

NOTE: This is hacky; since parameterized test aren't baked into the testing framework, things like "Intentional Errors" are a bit awkward and definitely not DRY. I would stay away from this if you absolutely need "Intentional Errors" for these tests; otherwise, it is passable (albeit, quite fugly):

// This must be AFTER "new Y.Test.Case({...});" so these tests will always run after those defined within
Y.Array.each([['  Hello world!', 'Hello world!'], ['  Hello world!   ', 'Hello world!']], function(input){
  testCase['string "' + input[0] + '" should have leading and trailing spaces removed'] = function(){
    var actual = input[1],
        result = input[0].replace(/^\s+|\s+$/g, '');
    Y.Assert.areEqual(result, actual);
  }
});

NOTE++: Before you ask...No, iterating over an array and calling Y.Assert multiple times is not a solution. This would cause two problems:

  1. It will only count as ONE test with multiple assertions.
  2. You are using multiple assertions in a single test method...if one of them fails, how do you know which one failed without further debugging?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment