jstonic/test/lib.js

54 lines
1.5 KiB
JavaScript

/**
* 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 = function( C, name, mock )
{
var SubC;
expect( function()
{
var dfn = {};
dfn[ 'override ' + name ] = mock;
SubC = C.extend( dfn );
} ).to.not.throw( Error );
// allows performing actions to trigger function for mock
return SubC;
};