/profess

Primary LanguageJavaScript

Profess

test your code as you write it

Usage:

profess
    .suite("weird integer testing") // add suite to describe your tests
    .want(1).toBeEqual(1)
    .want(42).toBeEqual(42)
    .test() // close suit by running test() method

    .suite("add more odd testing") // you can chain as much suits as you want
    .want(true).toBeEqual(false)
    .test()

add global coverage info to your tests (optional):

profess.withCoverage();
    // run your tests or suits here
profess.result();

Tests:

0. Fast checking:

profess.fast(value)(expectedValue)

profess.fast(100)(100);

result:

Fast checking:
100 equals 100
type = "number"

profess.fast(2)("2")

result:

Fast checking:
2 equals 2 but types are different: 2 is not of the type string as it should be

Note that you do not need suite() or anything else to perform fast checking
Keep in mind that fast tests are not recorded by withCoverage() method

1. Equality with type check:

toBeEqual(value)

profess.want(1).toBeEqual(2).test(); // fail  

2. Type matching check:

toMatchTypes(value)

const test = "Some string";
profess.want("testing this").toMatchTypes(test).test(); // Pass

3. Range check:

toBeInRange(min, max)

const value = 1337;
profess.want(value).toBeInRange(42, 9001).test(); // Pass

4. Existence check:

toExist()

let doesNotExist;
profess
    .want(0).toExist() // Pass
    .want(null).toExist() // Pass
    .want('').toExist() // Pass
    .want(doesNotExist).toExist() // Fail
    .test();

Note that this is not a falsy test

5. Absolute comparison:

absolute(value)

profess
    .want(-0).toBeEqual(+0) // Pass
    .want(-0).absolute(+0) // Fail
    .test();

6. Type check:

toBe.<Type>()
<Type> — Function, String, Number, Boolean, Null, Undefined

profess
    .want(1).toBe.Number() // Pass
    .want("bob").toBe.String() // Pass
    .want(null).toBe.Function() // Fail
    .test();