salep is a singleton object that manages all tests and cases. This object exposed to global scope as 'salep'.
Members
(static) reporter
Reporter object enables you track status of tests. It basically fires an event with formatted report message for each lifecycle events (testStart, caseStart, success etc.). You can use report message by logging to console or file wherever appropiate. Since console.log may not be available in global scope reporter doesn't log reports.
Properties:
Name | Type | Description |
---|---|---|
reporter |
Example
salep.on("report", function(message) {
console.log(message);
});
salep.reporter.running = true;
Methods
(static) case(name, func)
This function creates a new case inside salep scope with given name and case function. Cases created in salep scope doesn't have parent. When case function invoked if exception is thrown case would marked as failed otherwise case marked as succeded.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of the case |
func |
function | Case function |
Fires:
Example
salep.case('NewFailCaseInsalepScope', function() {
throw "Exception goes here";
});
(static) getResults() → {Result}
This method will return results of tests and cases from the beginning. If salep.stop is called at some point return value will just have the results after that call.
Returns:
Result object containing test results
- Type
- Result
(static) off(eventName, callbackToRemove)
This function allows removing callbacks from events. Every callback added with 'on' function can be removed with this function.
Parameters:
Name | Type | Description |
---|---|---|
eventName |
String | Event name to remove callback from |
callbackToRemove |
function | Callback to remove |
Example
function myCallback(test) {
// do some stuff
}
salep.on('testStart', myCallback);
...
salep.off('testStart', myCallback);
(static) on(eventName, callback)
This function enables adding callbacks to events. For one specific event there may be many callbacks.
Parameters:
Name | Type | Description |
---|---|---|
eventName |
String | Event name to add callback |
callback |
function | Callback |
Example
salep.on('fail', function(testCase) {
console.log(testCase.name + ' has failed!');
});
(static) run()
Enables salep testing. All the tests and cases before salep.run method executed will be counted and recorded as skipped.
- Deprecated:
- Since 0.2.0, salep starts in running mode as default. You don't need to use run function unless you used stop function.
- Source:
(static) skipNext()
This function helps skipping tests/cases. If you want to skip a case or test, run this function right before test or case definition.
Example
salep.skipNext();
salep.case("salep will skip this case", function() {
if (!someFunction()) {
throw "Exception";
}
});
(static) stop() → {Result}
Disables salep testing and returns all the collected information starting from last stop function invoked or the beginning of program (if stop function not invoked ever). After stop function invoked all following tests and cases will be counted and recorded as skipped.
- Deprecated:
- Since 0.2.0, when used it will cause salep skip tests and cases, this behaviour will continue until run function called.
- Source:
Returns:
Result object containing test results
- Type
- Result
(static) test(name, func)
This function creates a new test inside salep scope with given name and test function. Tests doesn't have success or fail status, they have cases. All the cases written inside test function is belong to named test.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of the test |
func |
function | Test function |
Fires:
Example
salep.test('NewTest', function() {
this.case('NewCase of NewTest', function() {
// Case code goes here
});
});
Events
caseStart
This event fires before starting a test case function.
Type:
fail
This event fires when a test case fails.
Type:
report
This event fires if reporter running status set to true and a lifecycle event occured. It sends formatted report message as argument.
Type:
- string
skip
This event fires when a test or case has skipped.
Type:
success
This event fires when a test case succeeds.
Type:
testStart
This event fires before starting a test function.