Eventable conformance test for removing unattached listeners

Testing much more would be very difficult, as the Eventable specifications
provide a great deal of flexibility on the part of the implementation.
events
Mike Gerwitz 2014-08-10 23:19:47 -04:00
parent b868a2da80
commit dffadf15cb
1 changed files with 27 additions and 11 deletions

View File

@ -18,8 +18,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* A conforming implementation must pass each of these tests. See the
* Eventable interface itself for additional requirements and documentation.
* A conforming implementation must pass each of these tests, but passing
* does not imply a conforming implementation; see the Eventable interface
* itself for additional requirements and documentation.
*
* To use these tests, invoke the exported function with a constructor
* function returning an instance of the SUT.
@ -85,6 +86,11 @@ module.exports = ctor =>
};
/**
* Note that by using _fvoid, we are implicitly testing the requirement
* that the listener shall not be required to declare any number of
* parameters (because we defined no parameters).
*/
function _commonTests( ctor, method )
{
/**
@ -165,20 +171,30 @@ function _commonTests( ctor, method )
function _onTests( ctor, on )
{
/**
* Note that by using _fvoid, we are implicitly testing the requirement
* that the listener shall not be required to declare any number of
* parameters (because we defined no parameters).
*/
describe( `#${on}`, () =>
{
_commonTests( ctor, on );
} );
describe( `#${on}`, () => _commonTests( ctor, on ) );
}
function _rmTests( ctor )
{
_commonTests( ctor, 'removeListener' );
/**
* Consider the goal of this operation: to ensure that the provided
* listener will not be invoked upon subsequent message dispatches to
* the provided event. It therefore stands to reason that, if the
* listener was not attached to begin with, that the job has been done,
* and therefore no error should be thrown.
*/
it( 'does not throw error when unhooking non-registered listener', () =>
{
let inst = ctor();
expect(
inst
.on( _ev, _fvoid )
.removeListener( _ev, ()=>{} ) )
.to.equal( inst );
} );
}