Skip to content

Latest commit

 

History

History
93 lines (71 loc) · 1.31 KB

File metadata and controls

93 lines (71 loc) · 1.31 KB

rJS Testing UnitTest unit

rJS Testing unit testing suite (UnitTest): Test arbitrary units of code based on deep expectation comparisons.

npm i -D @rapidjs.org/testing-unit
npx rjs-testing unit <tests-path>

Integrated in rapidjs-org/testing.

Test Anatomy

Expressions

.actual(expression: any)
.expected(expression: any)  // Identity assertion

Value-based Assertion

new UnitTest("Computes quotient of positive integers")
.actual(4 / 2)
.expected(2);

Error-based Assertion

new UnitTest("Computes quotient of positive integers")
.actual(() => 4 / x)
.error("x is not defined", ReferenceError);

View More Examples

Comparison Strategy

Unit tests work on arbitrary values. That being said, the comparison strategy implements soft (==) deep equality:

✅   SUCCESS

.actual({
  foo: {
    bar: 2
  }
})
.expected({
  foo: {
    bar: "2"
  }
})

❌   FAILURE

.actual({
  foo: {
    bar: 2
  }
})
.expected({
  foo: {
	bar: 4
  }
})
.actual({
  foo: {
    bar: 2
  }
})
.expected({
  foo: {
	bar: 2
  },
  baz: 4
})

© Thassilo Martin Schiepanski