Skip to content
/ tester Public

The "tester" is a simple JavaScript test module.

License

Notifications You must be signed in to change notification settings

cyrhla/tester

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tester

This is development (master) version.
For production version (relase) see http://github.com/cyrhla/tester/tree/v0.0.1

The "tester" is a simple JavaScript test module.


Install

npm install @cyrhla/tester

Usage

Unit tests

First, create the class:

// SomeClass.js

class SomeClass
{
    someMethod(someArgument)
    {
        return someArgument + '...'
    }

    // ...
}

Second, create the test:

// Tests/SomeClassTest.js

const Tester = require('@cyrhla/tester/Tester')
const SomeClass = require('../SomeClass')

class SomeClassTest extend Tester
{
    testSomeMethodReturnsString()
    {
        var obj = new SomeClass()

        this.assertSame('abc...', obj.someMethod('abc'))
    }

    // ...
}

Third, create the script*:

// scripts/test.js

'use strict'

new (require('@some/module/Tests/SomeClassTest'))()

Fourth, add the following lines to the package.json:

// ...
scripts: {
    "test": "node scripts/test.js"
}
// ...

Finally, execute the command via shell:

npm test

Typing

// somefile.js

const is = require('@cyrhla/tester/is')

var somefunc = function(arg) {
    if (is(arg, 'string', 'number')) {
        // ...
    }
    // ...
}
// ...

Validation

// somefile.js

const valid = require('@cyrhla/tester/valid')

var somefunc = function(arg) {
    valid(arg, 'string', 'number')

    // ...
}
// ...

API

Class Tester (Tester.js)

  • Tester( boolean: stopOnError = false, boolean: showOk = false, boolean: colorize = true, null|function|console.log: output = console.log )
    • toString(): string
    • getResultsJson: object
    • before(): undefined
    • after(): undefined
    • beforeEach(): undefined
    • afterEach(): undefined
    • assertSame( mixed: expected, mixed: actual ): undefined
    • assertEqual( mixed: expected, mixed: actual ): undefined
    • assertType( string: expected, mixed: actual ): undefined
    • assertInstanceOf( function: expected, function|object: actual ): undefined
    • assertError( string: errorName, function: callback, null|number: index = null ): undefined
    • createMocker( function: baseClass, mixed[]: args ): Mocker
    • static getBacktrace( Error: error, null|number: back = null ): string
    • static formatBytes( number: bytes, number: decimals = 1, string: separator = '.', number: kilo = 1000, string[]: units = [Bytes, KB, MB, GB, TB, PB, EB, ZB, YB] ): string
    • static type( mixed: arg ): string
    • static valid( *, *, ... ): mixed
    • static is( *, *, ... ): boolean

Class Mocker (Mocker/Mocker.js)

  • Mocker( function: baseClass, mixed[]: args = [] )
    • setProperty( mixed: key, mixed: value ): self
    • setMethod( mixed: key, function: callback ): self
    • compile(): object

Function is (is.js)

is( *, *, ... ): boolean

Function valid (valid.js)

valid( *, *, ... ): mixed

References

  1. Node.js Documentation

[*] Paths should be modified to the module.

About

The "tester" is a simple JavaScript test module.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published