Interface definition errors now contain class name when available
parent
5f739e604b
commit
da8be9affa
|
@ -148,8 +148,8 @@ function createNamedInterface( name, def )
|
||||||
if ( arguments.length > 2 )
|
if ( arguments.length > 2 )
|
||||||
{
|
{
|
||||||
throw Error(
|
throw Error(
|
||||||
"Expecting two arguments for named Interface definition; " +
|
"Expecting two arguments for definition of named Interface '" +
|
||||||
arguments.length + " given."
|
name + "'; " + arguments.length + " given."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,8 @@ function createNamedInterface( name, def )
|
||||||
if ( typeof def !== 'object' )
|
if ( typeof def !== 'object' )
|
||||||
{
|
{
|
||||||
throw TypeError(
|
throw TypeError(
|
||||||
"Unexpected value for named class definition; object expected"
|
"Unexpected value for definition of named Interface '" +
|
||||||
|
name + "'; object expected"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,15 +44,48 @@ var common = require( './common' ),
|
||||||
"Interface defined with name is returned as a valid interface"
|
"Interface defined with name is returned as a valid interface"
|
||||||
);
|
);
|
||||||
}, Error, "Interface accepts name" );
|
}, 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()
|
||||||
|
{
|
||||||
|
var name = 'Foo';
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Interface( 'Foo', 'Bar' );
|
Interface( name, 'Bar' );
|
||||||
}, TypeError, "Second argument to named interface must be the definition" );
|
|
||||||
|
// 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
|
// we should be permitted only two arguments
|
||||||
var args = [ 'Foo', {}, 'extra' ];
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Interface.apply( null, args );
|
Interface.apply( null, args );
|
||||||
|
@ -65,8 +98,16 @@ var common = require( './common' ),
|
||||||
}
|
}
|
||||||
catch ( e )
|
catch ( e )
|
||||||
{
|
{
|
||||||
|
var errstr = e.toString();
|
||||||
|
|
||||||
assert.notEqual(
|
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,
|
null,
|
||||||
"Named interface error should provide number of given arguments"
|
"Named interface error should provide number of given arguments"
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue