[#25] Added tests to ensure proper data is passed to validateMethod()
parent
6fd7ae8953
commit
fda002d252
|
@ -24,6 +24,55 @@
|
|||
|
||||
require( 'common' ).testCase(
|
||||
{
|
||||
caseSetUp: function()
|
||||
{
|
||||
var _self = this;
|
||||
|
||||
this.testArgs = function( args, name, value, keywords )
|
||||
{
|
||||
var pub = _self.members[ 'public' ],
|
||||
|
||||
// prev data
|
||||
pval_expect = null,
|
||||
pkeywords_expect = null,
|
||||
pval_given = null,
|
||||
pkeywords_given = null
|
||||
;
|
||||
|
||||
if ( pub[ name ] )
|
||||
{
|
||||
pval_expect = pub[ name ];
|
||||
pkeywords_expect = pval_expect.___$$keywords$$; // XXX
|
||||
|
||||
pval_given = args[ 3 ].member;
|
||||
pkeywords_given = args[ 4 ];
|
||||
}
|
||||
|
||||
_self.assertEqual( name, args[ 0 ],
|
||||
'Incorrect name passed to method validator'
|
||||
);
|
||||
|
||||
_self.assertStrictEqual( value, args[ 1 ],
|
||||
'Incorrect value passed to method validator'
|
||||
);
|
||||
|
||||
_self.assertStrictEqual( keywords, args[ 2 ],
|
||||
'Incorrect keywords passed to method validator'
|
||||
);
|
||||
|
||||
_self.assertStrictEqual( pval_expect, pval_given,
|
||||
'Previous data should contain prev value if overriding, ' +
|
||||
'otherwise null'
|
||||
);
|
||||
|
||||
_self.assertStrictEqual( pkeywords_expect, pkeywords_given,
|
||||
'Previous keywords should contain prev keyword if ' +
|
||||
'overriding, otherwise null'
|
||||
);
|
||||
};
|
||||
},
|
||||
|
||||
|
||||
setUp: function()
|
||||
{
|
||||
// stub factories used for testing
|
||||
|
@ -38,4 +87,60 @@ require( 'common' ).testCase(
|
|||
|
||||
this.members = this.sut.initMembers();
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* The validator can only do its job if we're providing it with the correct
|
||||
* information
|
||||
*/
|
||||
'Passes proper data to validator when not overriding': function()
|
||||
{
|
||||
var _self = this,
|
||||
called = false,
|
||||
|
||||
name = 'foo',
|
||||
value = function() {},
|
||||
keywords = {}
|
||||
;
|
||||
|
||||
this.mockValidate.validateMethod = function()
|
||||
{
|
||||
called = true;
|
||||
_self.testArgs( arguments, name, value, keywords );
|
||||
};
|
||||
|
||||
this.sut.buildMethod(
|
||||
this.members, {}, name, value, keywords, function() {}, 1, {}
|
||||
);
|
||||
|
||||
this.assertEqual( true, called, 'validateMethod() was not called' );
|
||||
},
|
||||
|
||||
|
||||
'Passes proper data to validator when overriding': function()
|
||||
{
|
||||
var _self = this,
|
||||
called = false,
|
||||
|
||||
name = 'foo',
|
||||
value = function() {},
|
||||
keywords = { 'override': true }
|
||||
;
|
||||
|
||||
// since we're overriding
|
||||
( this.members[ 'public' ].foo = function() {} ).___$$keywords$$ =
|
||||
{ 'public': true };
|
||||
|
||||
this.mockValidate.validateMethod = function()
|
||||
{
|
||||
called = true;
|
||||
_self.testArgs( arguments, name, value, keywords );
|
||||
};
|
||||
|
||||
this.sut.buildMethod(
|
||||
this.members, {}, name, value, keywords, function() {}, 1, {}
|
||||
);
|
||||
|
||||
this.assertEqual( true, called, 'validateMethod() was not called' );
|
||||
},
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue