Namespace: jasmine

jasmine

Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework.

Classes

CallTracker
Expectation
Spec
Spy
SpyStrategy
Suite

Members

<static> dbConnection :$.db.Connection

Managed legacy database connection, which behaves like jasmine.hdbConnection.
Type:
  • $.db.Connection
Since:
  • 1.7.3

<static> hdbConnection :$.hdb.Connection

Managed database connection. The connection is rolled back and closed after each beforeOnce, after each afterOnce, and after each set of it and its corresponding beforeEach and afterEach methods.
The connection is opened when used for the first time (or for the first time after it had been closed by the framework).

Assignments to the variable are supported.

Requires HANA Revision 90 (SPS09) or later. The connection can't yet be used with the Test Tools' APIs like the TableUtils.

Type:
  • $.hdb.Connection
Since:
  • 1.10.4

<static> MAX_PRETTY_PRINT_DEPTH :Number

Maximum levels of nesting that will be included when an object is pretty-printed
Type:
  • Number
Default Value:
  • 40

<static> tags

Container for tags. You can use this container to store your tags. It is recommended to store your tags in this container or some other variable rather than typing tags (usually strings) for each suite or spec in order to get an exception in case of a typo.
See:

Methods

<static> addProfile(name, definition)

Creates a new profile. If a profile named
name
already exists, it gets overwritten. In order to define the profile, you have two possibilities:
  • You can pass a function, which will be called for every spec—in case the profile is active. The respective spec gets executed if the function returns true, and is skipped otherwise.
  • You may also add a generic profile by passing a single tag or an array of tags. The resulting profile will filter out all specs which lack one or more of those tags.
Profiles can be activated by passing its name to the profile parameter of the test runner.
Parameters:
Name Type Description
name String Name of the profile
definition any | Array | function The definition of the profile; for details see the above description
See:
Example
// profiles.xsjslib
jasmine.tags.e2e = "e2e";
jasmine.tags.db = "db";
jasmine.tags.integration = "integration";

jasmine.addProfile("all", function() {
    return true;
});
jamsine.addProfile("no_db", function(tags) {
    return tags.indexOf(jasmine.tags.db) === -1;
});
jamsine.addProfile("e2e_with_db", [ jasmine.tags.e2e, jasmine.tags.db ]);
// myTest.xsjslib describe("My Test", function() { it("should test something", function() { }).addTags(); });

<static> any(clazz) → {Object}

Returns a matchable 'generic' object of the class type. For use in expecations of type when values don't matter.
Parameters:
Name Type Description
clazz Class
Returns:
matchable object of the type clazz
Type
Object
Example
// don't care about which function is passed in, as long as it's a function
expect(mySpy).toHaveBeenCalledWith(jasmine.any(Function));

<static> callHTTPService(path, httpMethod, body, headers, cookies) → {$.web.WebResponse}

Calls an HTTP service on the local instance and returns the response object.

Before you can use this function, you first need to adapt the HTTP destination sap.hana.testtools.unit.jasminexs.lib:localhost.xshttpdest to fit to your HANA instance. For "Authentication Type" we recommend Assertion Tickets, however this requires some preparation. For guidance see SAP HANA Administration Guide.
Parameters:
Name Type Argument Default Description
path String Absolute path to test resource (with '/' as package delimiter)
httpMethod $.net.http <optional>
$.net.http.GET Request method
body any | ArrayBuffer <optional>
Body of the request (e.g. for POST requests), can be any elemental JavaScript type or an ArrayBuffer
headers Object <optional>
Additional headers
cookies Object <optional>
A set of cookies to be sent
Since:
  • 1.6.5
Returns:
Response object (see XS JavaScript Reference)
Type
$.web.WebResponse
Example
describe("example for http tests", function() {

    it("should receive answer from service", function() {
        var requestBody = '{"param1":42,"param2":"xyz"}';
        var headers = {
            "Content-Type" : "application/json"
        };
        var response = jasmine.callHTTPService("/path/to/your/app/Service.xsjs", $.net.http.POST, requestBody, headers);

        expect(response.status).toBe($.net.http.OK);

        var body = response.body ? response.body.asString() : "";
        expect(body).toMatch(/regular expression that checks correct response/);
    });

});

<static> createSpyObj(baseName, methodNames) → {Object}

Creates a mock object in one single call. Useful when an object is needed that looks like an instance of some class—i.e. implements (parts of) its API—but has no functionality.
Parameters:
Name Type Description
baseName String name of spy class
methodNames Array array of names of methods to make spies
Returns:
Type
Object

<static> isSpy(putativeSpy) → {Boolean}

Determines whether an object is a spy.
Parameters:
Name Type Description
putativeSpy any
Returns:
Type
Boolean

<static> log(args)

All parameters are pretty-printed and concatenated together (space separated), then written to the current spec's output. Be careful not to leave calls to jasmine.log in production code.
Parameters:
Name Type Argument Description
args any <repeatable>
Values to be logged

<static> objectContaining(sample) → {Object}

Returns a matchable subset of a JSON object. For use in expectations when you don't care about all of the attributes on the object.
Parameters:
Name Type Description
sample Object sample
Returns:
matchable object for the sample
Type
Object
Example
// don't care about any other attributes than foo
expect(mySpy).toHaveBeenCalledWith(jasmine.objectContaining({ foo: 'bar' });