test-utils

primitive assert-methods for unit-testing

Per 30-08-2016. Zie de nieuwste versie.

Dit script moet niet direct worden geïnstalleerd - het is een bibliotheek voor andere scripts om op te nemen met de meta-richtlijn // @require https://update.greasyfork.org/scripts/22762/144812/test-utils.js

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==UserScript==
// @name            test-utils
// @name:de         test-utils
// @namespace       dannysaurus.camamba
// @version         0.1
// @license         MIT License
// @description     primitive assert-methods for unit-testing
// @description:de  primitive assert-methods for unit-testing
// ==/UserScript==
var LIB = LIB || {};
/**
 * @type {{assertTrue}}
 */
LIB.testUtils = (function() {
    'use strict';
    /**
     * Throws an error if assertion fails
     * @param {boolean} condition - condition to be checked</br><code>true</code> has the assertion succeed </br>false has the assertion fail (and throws an Error)
     * @param {string} [message] - debug-message to display if the assertion fails
     */
    var assertTrue = function(condition, message) {
        message = message || "Assertion failed";
        if (!condition) {
            throw new Error(message);
        }
    };
    /**
     *  Asserts that two values or objects are equal. Throws an Error if assertion fails.
     *  Strict comparison (<code>===</code>) is used to check for equality.
     * @param {*} expected - the expected value or object
     * @param {*} actual - the value or object to check against <code>expected</code>
     * @param {string} [message] - the identifying Error message for an assertion fail
     */
    var assertEquals = function(expected, actual, message) {
        assertTrue(expected === actual, message);
    };
    /**
     *  Asserts that two values or objects are equal. Throws an Error if assertion fails.
     *  Nonstrict comparison with type convertation (<code>==</code>) is used to check for equality.
     * @param {*} expected - the expected value or object
     * @param {*} actual - the value or object to check against <code>expected</code>
     * @param {string} [message] - the identifying Error message for an assertion fail
     */
    var assertEqualsNonStrict = function(expected, actual, message) {
        assertTrue(expected == actual, message);
    };
    return {
        assertTrue: assertTrue,
        assertEquals: assertEquals,
        assertEqualsNonStrict: assertEqualsNonStrict
    };
})();