1
0
Fork 0

Interface definition errors now contain class name when available

closure/master
Mike Gerwitz 2011-03-05 12:57:21 -05:00
parent 5f739e604b
commit da8be9affa
2 changed files with 51 additions and 9 deletions

View File

@ -148,8 +148,8 @@ function createNamedInterface( name, def )
if ( arguments.length > 2 )
{
throw Error(
"Expecting two arguments for named Interface definition; " +
arguments.length + " given."
"Expecting two arguments for definition of named Interface '" +
name + "'; " + arguments.length + " given."
);
}
@ -157,7 +157,8 @@ function createNamedInterface( name, def )
if ( typeof def !== 'object' )
{
throw TypeError(
"Unexpected value for named class definition; object expected"
"Unexpected value for definition of named Interface '" +
name + "'; object expected"
);
}

View File

@ -44,15 +44,48 @@ var common = require( './common' ),
"Interface defined with name is returned as a valid interface"
);
}, Error, "Interface accepts name" );
} )();
// the second argument must be an object
assert.throws( function()
/**
* The interface definition, which equates to the body of the interface, must be
* an object
*/
( function testNamedInterfaceDefinitionRequiresThatDefinitionBeAnObject()
{
Interface( 'Foo', 'Bar' );
}, TypeError, "Second argument to named interface must be the definition" );
var name = 'Foo';
try
{
Interface( name, 'Bar' );
// if all goes well, we'll never get to this point
assert.fail(
"Second argument to named interface must be the definition"
);
}
catch ( e )
{
assert.notEqual(
e.toString().match( name ),
null,
"Interface definition argument count error string contains " +
"interface name"
);
}
} )();
/**
* Extraneous arguments likely indicate a misunderstanding of the API
*/
( function testNamedInterfaceDefinitionIsStrictOnArgumentCount()
{
var name = 'Foo',
args = [ name, {}, 'extra' ]
;
// we should be permitted only two arguments
var args = [ 'Foo', {}, 'extra' ];
try
{
Interface.apply( null, args );
@ -65,8 +98,16 @@ var common = require( './common' ),
}
catch ( e )
{
var errstr = e.toString();
assert.notEqual(
e.toString().match( args.length + ' given' ),
errstr.match( name ),
null,
"Named interface error should provide interface name"
);
assert.notEqual(
errstr.match( args.length + ' given' ),
null,
"Named interface error should provide number of given arguments"
);