Skip to content

jlongyam/Test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub ReadMe NPM

Test

Simple Test utility.

  • deepCompare for nested Array and Object
  • Automatically run
  • Automatically message

Demo

Install

npm i @jlongyam/test -D

Script

test/test.js

import Test from "@jlongyam/test";

// Only 4 keywords
const { describe, it, assert } = Test();

describe("Test", () => {
  // Container
  it(() => {
    // Section
    assert(2 + 3 === 5); // True
  });
  it(() => {
    assert(-1 + 5 === 5); // False
  });
  it(() => {
    assert(0 + 0 === 0);
  });
});

package.json:

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

Terminal

npm test
Test
✔ should 5
✖ should 4 - Expected false
✔ should 0

Usage

How to test Array or Object:

Just like console.assert, comparing using === will fail,

There are two method:

  • use String(A) === String(B)
  • use deepCompare [A,B] bracket.

Example:

describe("Test", () => {
  it("assert ([a, b])", () => {
    let a = [1, 2];
    let b = [1, 2, 3];
    a.push(3);
    // PASS
    assert([a, b]);
  });
  it("assert (a === b)", () => {
    let a = [1, 2];
    let b = [1, 2, 3];
    a.push(3);
    // FAIL
    assert(a === b);
  });
  it("assert (String(a) === String(b))", () => {
    let a = [1, 2];
    let b = [1, 2, 3];
    a.push(3);
    // PASS
    assert(String(a) === String(b));
  });
});

More usage see DOCS

Browser support

Desktop

Name Version
IE 8+
Safari 5+
Firefox 52+
Chrome 50+

Mobile

System Version
Android API 34+
Iphone Latest

Changelog

v0.6.0

Simple it

the message argument is optional, example:

it(() => {
  let one = { value: "ONE" };
  let two = { value: "TWO" };
  assert([one, two]); // <- report chunk
});

It will reported assert section automatically: