test-utils

primitive assert-methods for unit-testing

Detta skript bör inte installeras direkt. Det är ett bibliotek för andra skript att inkludera med meta-direktivet // @require https://update.greasyfork.org/scripts/22762/144820/test-utils.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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';
    function messageNotEquals(expected, actual) {
        return "Assertion failed. expected: " + expected + " actual: " + actual
    }
    /**
     * 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>
     */
    var assertEquals = function(expected, actual) {
        var message = messageNotEquals(expected, actual);
        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>
     */
    var assertEqualsNonStrict = function(expected, actual) {
        var message = messageNotEquals(expected, actual);
        assertTrue(expected == actual, message);
    };
    return {
        assertTrue: assertTrue,
        assertEquals: assertEquals,
        assertEqualsNonStrict: assertEqualsNonStrict
    };
})();