@robinpath/assert
0.1.2Node.jsPublicTesting assertions: equal, deepEqual, truthy, falsy, type checks, includes, matches, throws, and more
Assert
Testing assertions: equal, deepEqual, truthy, falsy, type checks, includes, matches, throws, and more
Package: @robinpath/assert | Category: Utility | Type: Utility
Authentication
No authentication required. All functions are available immediately.
Use Cases
Use the assert module when you need to:
- Assert two values are strictly equal (===) -- Use
assert.equalto perform this operation - Assert two values are not equal -- Use
assert.notEqualto perform this operation - Assert deep equality of two values -- Use
assert.deepEqualto perform this operation - Assert value is truthy -- Use
assert.truthyto perform this operation - Assert value is falsy -- Use
assert.falsyto perform this operation
Quick Reference
| Function | Description | Returns |
|---|---|---|
equal | Assert two values are strictly equal (===) | True if equal, throws otherwise |
notEqual | Assert two values are not equal | True if not equal |
deepEqual | Assert deep equality of two values | True if deeply equal |
truthy | Assert value is truthy | True if truthy |
falsy | Assert value is falsy | True if falsy |
isNull | Assert value is null or undefined | True if null/undefined |
isNotNull | Assert value is not null/undefined | True if not null |
isType | Assert typeof value matches expected type | True if type matches |
includes | Assert array/string includes a value | True if includes |
matches | Assert string matches a regex pattern | True if matches |
throws | Assert that a function throws | True if throws |
lengthOf | Assert array/string has specific length | True if length matches |
hasProperty | Assert object has a specific property | True if has property |
isAbove | Assert number is above threshold | True if above |
isBelow | Assert number is below threshold | True if below |
Functions
equal
Assert two values are strictly equal (===)
Module: assert | Returns: boolean -- True if equal, throws otherwise
assert.equal $a $b
| Parameter | Type | Required | Description |
|---|---|---|---|
actual | any | Yes | Actual value |
expected | any | Yes | Expected value |
notEqual
Assert two values are not equal
Module: assert | Returns: boolean -- True if not equal
assert.notEqual $a $b
| Parameter | Type | Required | Description |
|---|---|---|---|
actual | any | Yes | Actual value |
expected | any | Yes | Value to not match |
deepEqual
Assert deep equality of two values
Module: assert | Returns: boolean -- True if deeply equal
assert.deepEqual $obj1 $obj2
| Parameter | Type | Required | Description |
|---|---|---|---|
actual | any | Yes | Actual value |
expected | any | Yes | Expected value |
truthy
Assert value is truthy
Module: assert | Returns: boolean -- True if truthy
assert.truthy $val
| Parameter | Type | Required | Description |
|---|---|---|---|
value | any | Yes | Value to check |
falsy
Assert value is falsy
Module: assert | Returns: boolean -- True if falsy
assert.falsy $val
| Parameter | Type | Required | Description |
|---|---|---|---|
value | any | Yes | Value to check |
isNull
Assert value is null or undefined
Module: assert | Returns: boolean -- True if null/undefined
assert.isNull $val
| Parameter | Type | Required | Description |
|---|---|---|---|
value | any | Yes | Value to check |
isNotNull
Assert value is not null/undefined
Module: assert | Returns: boolean -- True if not null
assert.isNotNull $val
| Parameter | Type | Required | Description |
|---|---|---|---|
value | any | Yes | Value to check |
isType
Assert typeof value matches expected type
Module: assert | Returns: boolean -- True if type matches
assert.isType $val "string"
| Parameter | Type | Required | Description |
|---|---|---|---|
value | any | Yes | Value to check |
type | string | Yes | Expected type string |
includes
Assert array/string includes a value
Module: assert | Returns: boolean -- True if includes
assert.includes "hello" "ell"
| Parameter | Type | Required | Description |
|---|---|---|---|
haystack | any | Yes | Array or string to search |
needle | any | Yes | Value to find |
matches
Assert string matches a regex pattern
Module: assert | Returns: boolean -- True if matches
assert.matches "hello" "^h"
| Parameter | Type | Required | Description |
|---|---|---|---|
str | string | Yes | String to test |
pattern | string | Yes | Regex pattern |
throws
Assert that a function throws
Module: assert | Returns: boolean -- True if throws
assert.throws $fn
| Parameter | Type | Required | Description |
|---|---|---|---|
fn | string | Yes | Function to call |
lengthOf
Assert array/string has specific length
Module: assert | Returns: boolean -- True if length matches
assert.lengthOf $arr 3
| Parameter | Type | Required | Description |
|---|---|---|---|
value | any | Yes | Array or string |
length | number | Yes | Expected length |
hasProperty
Assert object has a specific property
Module: assert | Returns: boolean -- True if has property
assert.hasProperty $obj "name"
| Parameter | Type | Required | Description |
|---|---|---|---|
obj | object | Yes | Object to check |
property | string | Yes | Property name |
isAbove
Assert number is above threshold
Module: assert | Returns: boolean -- True if above
assert.isAbove 5 3
| Parameter | Type | Required | Description |
|---|---|---|---|
value | number | Yes | Number to check |
threshold | number | Yes | Threshold |
isBelow
Assert number is below threshold
Module: assert | Returns: boolean -- True if below
assert.isBelow 3 5
| Parameter | Type | Required | Description |
|---|---|---|---|
value | number | Yes | Number to check |
threshold | number | Yes | Threshold |
Error Handling
All functions throw on failure. Common errors:
| Error | Cause |
|---|---|
Expected ${JSON.stringify(args[0])} to equal ${JSON.stringify(args[1])} | Check the error message for details |
Expected values to not be equal: ${JSON.stringify(args[0])} | Check the error message for details |
Expected deep equality.\nActual: ${JSON.stringify(args[0])}\nExpected: ${JSON.stringify(args[1])} | Check the error message for details |
Expected truthy value, got: ${JSON.stringify(args[0])} | Check the error message for details |
Expected falsy value, got: ${JSON.stringify(args[0])} | Check the error message for details |
Expected null/undefined, got: ${JSON.stringify(args[0])} | Check the error message for details |
Expected non-null value, got null/undefined | Check the error message for details |
Expected array to include ${JSON.stringify(needle)} | Check the error message for details |
@desc "Equal and validate result"
do
set $result as assert.equal $a $b
if $result != null
print "Success"
else
print "No result"
end
enddo
Recipes
1. Multi-step Assert workflow
Chain multiple assert operations together.
@desc "Equal, not equal, and more"
do
set $r_equal as assert.equal $a $b
set $r_notEqual as assert.notEqual $a $b
set $r_deepEqual as assert.deepEqual $obj1 $obj2
print "All operations complete"
enddo
2. Safe equal with validation
Check results before proceeding.
@desc "Equal and validate result"
do
set $result as assert.equal $a $b
if $result != null
print "Success: " + $result
else
print "Operation returned no data"
end
enddo
Related Modules
- json -- JSON module for complementary functionality
Versions (1)
| Version | Tag | Published |
|---|---|---|
| 0.1.2 | latest | 1 months ago |
Related Modules
@robinpathv0.1.4
SMTP email sending and address parsing for RobinPath
hash
JS@robinpathv0.1.3
Cryptographic hashing utilities: MD5, SHA family, HMAC, CRC32, file hashing, UUID v5 generation, secure random bytes, and content fingerprinting
csv
JS@robinpathv0.1.2
Parse and stringify CSV data
apollo
JS@robinpathv0.1.2
Apollo module for RobinPath.
$ robinpath add @robinpath/assert
