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 expectedany -
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 expectedNumber precisionNumber <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 expectedany -
toBeLessThan(expected)
-
Matcher that compares the actual to the expected using <.
Parameters:
Name Type Description expectedany -
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 expectedany -
toEqual(expected)
-
Matcher that compares the actual to the expected using common sense equality. Handles objects, arrays, etc.
Parameters:
Name Type Description expectedany -
toEqualObject(expected)
-
Compares two objects. Since the output format of the standard 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 expectedObject 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 expectedany <optional>
<repeatable>
Expected parameters -
toMatch(regexp, modifiers)
-
Matcher that compares the actual to the expected using a regular expression.
Parameters:
Name Type Argument Description regexpRegExp | String Regular expression that the actual value is tested against modifiersString <optional>
Flags for regexp; will be ignored ifregexpis 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
- 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
Parameters:
Name Type Description expectedObject | Array | $.db.ResultSet | TableDataSet expected table-like data keyFieldsArray 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 errorany <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 typeOrMessagefunction | String <optional>
An error class if messageparameter is provided, an error message otherwisemessageString <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");