Dynamic test using the data object to pass in the function name?

I have a large number of functions in a class that have the same behavior.
I am trying to would like to just create a list of functions and then execute that specific suite against each function.

        var data = [

	    for( var thisData in data ){

	        describe( "Trying #thisData#", function(){

				beforeEach( data={ myData = thisData }, body=function( currentSpec, data ){
            		targetData = arguments.data.myData;

	            it( "Should require corpId argument", function(){                	            	
	            	var testFunction = subjectCFC["set_#targetData#"];
                    testFunction(corpId=2, settingName=targetData, value='string value');

	                expect(	function(){
	                	var testFunction = subjectCFC["set_#targetData#"];
	                    testFunction(corpId=2, settingName = targetData, value='string value');
	                } ).toThrow();                            

	            afterEach( data={ myData = thisData }, body=function( currentSpec, data ){
	                targetData = arguments.data.myData;
    } );

And yes I have those lines repeated outside of the closure because my test is looking for a throw and I need to see the actual error for debugging.

This kind of works in that it does execute the method in the variable but the problem is that the testFunction variable only contains that specific function and is separated from the other functions in the class.
Does anyone know a way that I can do these kind of test without having to create each individually.

I suspect there is some can’t see the forest because the trees are in my way action going on here.

The problem is that you are only binding the top level describe() with the data. The internal it() functions are not, so they will be linked with the last reference only. YOu will have to cascade it fully down to the it() functions as well using the data argument.


var types = [ "success", "info", "warn", "error" ];
			for ( var thisType in types ) {
					title = "can set #thisType# messages",
					data  = { type : thisType },
					body  = function( data ){
						m.setMessage( data.type, "test message" );
						expect( m.isEmptyMessage() ).toBeFalse();
						expect( m.getMessage().message ).toBe( "test message" );
						expect( m.getMessage().type ).toBe( data.type );

Thank you, I will give that a try.

This definitely worked for me thank you.