diff --git a/lib/interface.js b/lib/interface.js index 30900eb..47051d0 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -203,22 +203,25 @@ var extend = ( function( extending ) property: function() { throw TypeError( - "Properties are not permitted within Interface " + - "definitions (did you forget the 'abstract' keyword?)" + "Property not permitted within definition of " + + "Interface '" + iname + "' (did you forget the " + + "'abstract' keyword?)" ); }, getter: function() { throw TypeError( - "Getters are not permitted within Interface definitions" + "Getter not permitter within definition of Interface '" + + iname + "'" ); }, setter: function() { throw TypeError( - "Setters are not permitted within Interface definitions" + "Setter within definition of Interface '" + + iname + "'" ); }, @@ -227,8 +230,9 @@ var extend = ( function( extending ) if ( !is_abstract ) { throw TypeError( - "Only abstract methods are permitted within " + - "Interface definitions" + "Concrete method not permitted in declaration of " + + "Interface '" + iname + "'; please declare as " + + "abstract." ); } diff --git a/test/test-interface-name.js b/test/test-interface-name.js index dc9612b..a50f101 100644 --- a/test/test-interface-name.js +++ b/test/test-interface-name.js @@ -145,3 +145,76 @@ var common = require( './common' ), ); } )(); + +( function testDeclarationErrorsProvideInterfaceNameIsAvailable() +{ + var name = 'Foo', + + // functions used to cause the various errors + tries = [ + // properties + function() + { + Interface( name, { prop: 'str' } ); + }, + + // methods + function() + { + Interface( name, { method: function() {} } ); + }, + ] + ; + + // if we have getter/setter support, add those to the tests + if ( Object.defineProperty ) + { + // getter + tries.push( function() + { + var obj = {}; + Object.defineProperty( obj, 'getter', { + get: function() {}, + enumerable: true, + } ); + + Interface( name, obj ); + } ); + + // setter + tries.push( function() + { + var obj = {}; + Object.defineProperty( obj, 'setter', { + set: function() {}, + enumerable: true, + } ); + + Interface( name, obj ); + } ); + } + + // gather the error strings + var i = tries.length; + while ( i-- ) + { + try + { + // cause the error + tries[ i ](); + + // we shouldn't get to this point... + assert.fail( "Expected error. Something's wrong." ); + } + catch ( e ) + { + // ensure the error string contains the interface name + assert.notEqual( + e.toString().match( name ), + null, + "Error contains interface name when available (" + i + ")" + ); + } + } +} )(); +