npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mangar2/unittest

v1.5.0

Published

publishes messages to a MQTT-Style HTTP broker

Downloads

4

Readme

Abstract

This module provides a simple class to support unit tests , this is not a framework . Use "testrun" , as a simple uinit test framework

Contents

Meta

| | | | --- | --- | | File | unittest.js | | Abstract | This module provides a simple class to support unit tests , this is not a framework . Use "testrun" , as a simple uinit test framework | | Author | Volker Böhm | | Copyright | Copyright ( c ) 2020 Volker Böhm | | License | This software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose . |

Class UnitTest

new UnitTest(verbose, debug)

Creates an object supporting unit tests

Example

const unitTest = new UnitTest(true, true)
unitTest.assertEqual('1', '1', 'equal')
unitTest.assertTrue(true, 'true')
unitTest.assertFalse(false, 'false')
unitTest.success('success')
unitTest.log('just a log')
unitTest.assertDeepEqual({ a: 'b' }, { a: 'b' })
unitTest.expectException(() => { throw new Error('Hello World') }, 'Error', 'message')

UnitTest Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | verbose | boolean | true to give more output | | | debug | bool | true , to print a stack trace on fail | |

UnitTest Members

| Name | Type | description | | ------------ | ------------ | ------------ | | debug | bool | Set debug to true , to print a stack trace on fail | | verbose | bool | Set verbose to true to print all success infos |

UnitTest Methods

assertDeepEqual

assertDeepEqual (a, b, message) => {boolean}

Compares two objects deeply

assertDeepEqual Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | a | any | first object to compare | | | b | any | second object to compare | | | message | string | message to show | |

assertDeepEqual returns

| Type | Description | | ---- | ----------- | | boolean | true/false based on success |

assertEqual

assertEqual (a, b, message) => {boolean}

Compares two values , fails if they are not equal " = = "

assertEqual Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | a | any | first value | | | b | any | second value | | | message | string | info message on success/fail | |

assertEqual returns

| Type | Description | | ---- | ----------- | | boolean | true/false based on success |

assertFalse

assertFalse (test, message) => {boolean}

Tests a value for beeing false , fails if the value is true

assertFalse Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | test | boolean | test value | | | message | string | info message on success/fail | |

assertFalse returns

| Type | Description | | ---- | ----------- | | boolean | true/false based on success |

assertTrue

assertTrue (test, message) => {boolean}

Tests a value for beeing true , fails if the value is false

assertTrue Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | test | boolean | test value | | | message | string | info message on success/fail | |

assertTrue returns

| Type | Description | | ---- | ----------- | | boolean | true/false based on success |

delay

delay (timeInMilliseconds) => {Promise}

Pauses the execution for a while ( needs to "wait" ) for the result .

delay Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | timeInMilliseconds | number | delay in milliseconds | |

delay returns

| Type | Description | | ---- | ----------- | | Promise | to wait for |

expectException

expectException (callback, instance) => {boolean}

Runs a function and checks for a returned expection

expectException Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | callback | function | function causing the expection | | | instance | string | instance of the exception | |

expectException returns

| Type | Description | | ---- | ----------- | | boolean | true on expection |

fail

fail (message)

Adds a failure

fail Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | message | string | message to print on failure | |

log

log (info)

Logs a string , if verbose

log Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | info | string | info to log | |

logError

logError (err)

Logs an error usually from a catch section

logError Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | err | Error, string | error information | |

showResult

showResult (expectedAmount)

Show the overall test result . Exits the process with "1" on failure

showResult Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | expectedAmount | number | expected amount of positive test in the current run | |

success

success (message)

Adds a success

success Parameters

| Name | Type | Description | | ---------- | ------------ | ----------------- | | message | string | message to print on success ( if verbose is true ) | |

validateRec

validateRec (toValidate, expected, path, exact)

Checks an element recursively for differences . It only checks values that are specified in "expected" and ignores additional data in result . This enables us to specify only the values that we like to check in the test cases .

validateRec Parameters

| Name | Type | Attribute | Default | Description | | ---------- | ------------ | ------------ | ------------ | ----------------- | | toValidate | any | | | element to be validated | | | expected | any | | | description of expected element | | | path | string | | | path to the element to compare | | | exact | string | optional | false | | |

validateRec throws

| Type | Description | | ---- | ----------- | | string | first difference |

validateResult

validateResult (result, expected, path, exact) => {boolean}

Validates a result object against an expected object . It validates with exact equal , that "result" has all object properties of expected .

validateResult Parameters

| Name | Type | Attribute | Default | Description | | ---------- | ------------ | ------------ | ------------ | ----------------- | | result | Object | | | object to be validated | | | expected | Object | | | expected object | | | path | string | | | path to be displayed on success/error | | | exact | boolean | optional | false | true , if result may not have additional properties | |

validateResult returns

| Type | Description | | ---- | ----------- | | boolean | true , if the test is ok |