hhassert
hhassert is simple assertion library for Hack.
You can use easily as assert module of nodejs.
Basic Usage
It will specify the hhassert\Assert in the use keyword.
use hhassert\Assert;
Assert::ok(1 === 1); //Passed
Assert::ok("a" === "b"); //Failed
Assert::equal("a", "a"); //Passed
Assert::equal(1, 1); //Passed
Assert::equal(1.0, 2.0); //Failed
Assert::notEqual("a", "b"); //Passed
Assert::notEqual("a", "a"); //Failed
Assert::throws(() ==> {
throw new InvalidArgumentException("exception!!");
}, InvalidArgumentException::class);
Custom matcher
You can be the registration of the matcher in the configure method. Matcher specified in the lambda expression.
Assert::configure((ContextBuilder $builder) ==> {
$builder->registerMatcher('custom_matcher', (...) ==> {
list($a, $b) = func_get_args();
if ($a !== $b) {
throw new AssertionFailedException("custom matcher");
}
});
});
Assert::custom_matcher("a", "b");
Run the test
composer install
composer test