Expectations
Expectations are self-concatenated strings that evaluate an actual value to an expected value or condition. These are initiated by the global TestBox method called expect() which takes in a value called the actual value or expectAll() which takes in an array or struct which will be the actual value. It is concatenated in our expectations DSL with a matcher function that will most likely take in an expected value or condition to test. You can also concatenate the matchers and do multiple evaluations on a single actual value.
Matchers
Each matcher implements a comparison or evaluation of the actual value and an expected value or condition. It is responsible for either passing or failing this evaluation and reporting it to TestBox. Each matcher also has a negative counterpart assertion by just prefixing the call to the matcher with a not expression.
function run(){
describe("The 'toBe' matcher evaluates equality", function(){
it("and has a positive case", function(){
expect( true ).toBe( true );
});
it("and has a negative case", function(){
expect( false ).notToBe( true );
});
});
describe("Collection expectations", function(){
it( "can be done easily with TestBox", function(){
expectAll( {a:2,b:4,c:6} ).toSatisfy( function(x){ return 0 == x%2; });
});
});
}Included Matchers
TestBox has a plethora (That's Right! I said Plethora) of matchers that are included in TestBox. The best way to see all the latest matchers is to visit our API and digest the testbox.system.Expectation class. There is also the ability to register and write custom matchers in TestBox via our addMatchers() function at runtime.
Custom Matchers
You can also build and register custom matchers. Please visit the Custom Matchers chapter to read more about custom matchers.
Was this helpful?