Constructor
new Test()
Example
salep.test("A test", function() {
salep.case("object creation with string", function() {
test.serverStatus = getServerStatus();
// Continue to case
});
});
...
var result = salep.getResults();
result.tests.forEach(function(test) {
if (test.name === "A test") {
console.log("Server status was '" + test.serverStatus + "' when test ran");
}
});
Members
cases :Array.<Case>
This property is cases array which hold all cases defined in test.
Type:
- Array.<Case>
level :number
Indicates nesting level of test. A test can have tests too, every nested case will have +1 level of its parent test. Root tests, created using salep.test, have level of 0.
Type:
- number
name
Name of the test.
Properties:
Name | Type | Description |
---|---|---|
name |
string |
skipped :boolean
Indicates if test skipped or not. If a test is skipped all cases inside test will not be counted in anywhere.
Type:
- boolean
tests :Array.<Test>
This property holds all nested tests defined in current test. All nested tests will have +1 level of current test.
Type:
- Array.<Test>
Methods
afterEach()
This function allows setting a callback that runs after each case. If after each callback fails (throws exception), it causes all cases to be counted as failed too. After each callback should be set before all case definitons.
Example
salep.test("File test", function() {
var filePath = "path/to/file";
// After each case remove file
this.afterEach(function() {
removeFile(filePath);
});
this.case("write to file case", function() {
// Assume below function creates file in filePath
writeToFile(filePath, "Text");
});
});
beforeEach()
This function allows setting a callback that runs before each case. With this functionality you can set up environment you will use in cases. If before each callback fails (throws exception), it causes all cases to be counted as failed too. Before each callback should be set before all case definitions.
Example
salep.test("A test", function() {
var instance = null;
this.beforeEach(function() {
instance = new ClassToTest();
});
this.case("foo case", function() {
// This instance created before case runs
instance.foo();
});
this.case("bar case", function() {
// This instance isn't the same instance with foo case's instance
instance.bar();
});
});
case(name, func)
This function creates a new case inside current test scope with given name and case function.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of the case |
func |
function | Case function |
Fires:
Example
salep.test('A test', function() {
this.case('Should succeed', function() {
// Case code
});
});
test(name, func)
This function creates a new test inside current test scope with given name and test function.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Name of the test |
func |
function | Test function |
Fires:
Example
salep.test('A test', function() {
this.test('An inner test', function() {
this.case('This case belongs to inner test', function() {
// Case
});
});
});