Class: Expectation

jasmine. Expectation

new Expectation()

Instances of jasmine.Expectation are returned by expect.

Members

not :jasmine.Expectation

Inverts all matchers
Type:

Methods

toBe(expected)

Matcher that compares the actual to the expected using ===.
Parameters:
Name Type Description
expected any

toBeCloseTo(expected, precision)

Matcher that checks that the expected item is equal to the actual item up to a given level of decimal precision.
Parameters:
Name Type Argument Default Description
expected Number
precision Number <optional>
2 as number of decimal places

toBeDefined()

Matcher that compares the actual to
undefined
.

toBeFalsy()

Matcher that boolean nots the actual.

toBeGreaterThan(expected)

Matcher that compares the actual to the expected using >.
Parameters:
Name Type Description
expected any

toBeLessThan(expected)

Matcher that compares the actual to the expected using <.
Parameters:
Name Type Description
expected any

toBeNaN()

Matcher that compares the actual to NaN.

toBeNull()

Matcher that compares the actual to null.

toBeTruthy()

Matcher that boolean not-nots the actual.

toBeUndefined()

Matcher that compares the actual to
undefined
.

toContain(expected)

Matcher that checks that the expected item is an element in the actual array.
Parameters:
Name Type Description
expected any

toEqual(expected)

Matcher that compares the actual to the expected using common sense equality. Handles objects, arrays, etc.
Parameters:
Name Type Description
expected any

toEqualObject(expected)

Compares two objects. Since the output format of the standard jasmine.Expectation.prototype.toEqual matcher in some instances makes it hard to spot the actual differences between two complicated objects, this matcher provides an improved reporting of the found discrepancies. Similar to the
toMatchData
function, it reports differences in objects in three different categories: missing properties, extraneous properties and matching properties with different values.
Parameters:
Name Type Description
expected Object any object

toHaveBeenCalled()

Matcher that checks to see if the actual, a Jasmine spy, was called.

toHaveBeenCalledWith(expected)

Matcher that checks to see if the actual, a Jasmine spy, was called with a set of parameters.
Parameters:
Name Type Argument Description
expected any <optional>
<repeatable>
Expected parameters

toMatch(regexp, modifiers)

Matcher that compares the actual to the expected using a regular expression.
Parameters:
Name Type Argument Description
regexp RegExp | String Regular expression that the actual value is tested against
modifiers String <optional>
Flags for
regexp
; will be ignored if
regexp
is not a string

toMatchData(expected, keyFields)

Compares two sets of data. Simplifies comparisons between table like data, typically to ensure that the result set of some SQL query matches a predefined set of data. Both actual and expected data have to be provided in one of the following formats (but not necessarily the same):
  • An array of objects; Each object represent a row; Each property of those objects represents a cell (property name = column name, property value = data)
  • An object; Each property represents a column (property name = column name, property value = data); Each property must be an array
  • An instance of module:tableDataSet~TableDataSet
  • An instance of
    $.db.ResultSet
With respect to the row key, differences between the actual and expected data will be reported in three different categories:
  • rows only present in the expected, but not the actual data
  • rows only present in actual, but not in the expected data
  • rows in the actual and expected data whose key fields match, but exhibit different values in other columns
The matcher only considers those columns contained in the expected data set; values in additional columns only present within the actual data set are ignored in the comparison.
Parameters:
Name Type Description
expected Object | Array | $.db.ResultSet | TableDataSet expected table-like data
keyFields Array names of the columns making up a unique row key for the matcher function to identify corresponding rows in the actual and expected data sets
Example
it("should match JSON", function() {
    var dataAsJSON = {
        "ORDER_ID" : [ "1", "2" ],
        "OPEN_AMOUNT" : [ 10.1, 20.2 ],
    };
    var sql = 'select * from SAP_HANA_TEST_DEMO."sap.hana.testtools.demo.objects::ORDERS"';
    var statement = this.dbConnection.prepareStatement(sql);
    var resultSet = statement.executeQuery();
    expect(resultSet).toMatchData(dataAsJSON, [ "ORDER_ID" ]);
});

toThrow(error)

Matcher that checks that the expected exception was thrown by the actual function.
Parameters:
Name Type Argument Description
error any <optional>
The error that is expected to be thrown

toThrowError(typeOrMessage, message)

Matcher that checks that the expected exception was thrown by the actual function.
Parameters:
Name Type Argument Description
typeOrMessage function | String <optional>
An error class if
message
parameter is provided, an error message otherwise
message String <optional>
An error message
Example
function testMe() {
    1();
}

// check only message
expect(testMe).toThrowError("1 is not a function");

// check type and message
expect(testMe).toThrowError(TypeError, "1 is not a function");