jstonic/test/lib.js

49 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2014-05-03 00:40:27 -04:00
/**
* Common test abstractions
*
* Copyright (C) 2014 Mike Gerwitz
*
* This file is part of jsTonic.
*
* jstonic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var expect = require( 'chai' ).expect;
/**
* Asserts that a method on C can be overridden, and executes mock code as part
* of the override method
*
* The generated subclass is returned, allowing methods to be invoked to trigger
* the execution of the overridden method.
*
* @param {Class} C class to attempt override on
* @param {string} name name of method to override
* @param {Function} mock mock function for override
*
* @return {Class} generated subtype
*/
exports.checkOverride = ( C, name, mock ) =>
2014-05-03 00:40:27 -04:00
{
var SubC;
expect( () => SubC = C.extend( { [ `override ${name}` ]: mock } ) )
.to.not.throw( Error );
2014-05-03 00:40:27 -04:00
// allows performing actions to trigger function for mock
return SubC;
};