Methods
(static) toBe(expected) → {void}
- Source:
Checks whether a received value equals the expected value with string equality operator === .
Example
describe('Example toBe Test', function () {
test('Check a return of the return12Func', function () {
var retVal = return12Func();
expect(retVal).toBe(12);
});
});
Parameters:
| Name |
Type |
Description |
expected |
any
|
|
Returns:
-
Type
-
void
(static) toBeDefined() → {void}
- Source:
Returns:
-
Type
-
void
(static) toBeFalsy() → {void}
- Source:
Returns:
-
Type
-
void
(static) toBeGreaterThan(expected) → {void}
- Source:
Parameters:
| Name |
Type |
Description |
expected |
number
|
|
Returns:
-
Type
-
void
(static) toBeGreaterThanOrEqual(expected) → {void}
- Source:
Parameters:
| Name |
Type |
Description |
expected |
number
|
|
Returns:
-
Type
-
void
(static) toBeLessThan(expected) → {void}
- Source:
Parameters:
| Name |
Type |
Description |
expected |
number
|
|
Returns:
-
Type
-
void
(static) toBeLessThanOrEqual(expected) → {void}
- Source:
Parameters:
| Name |
Type |
Description |
expected |
number
|
|
Returns:
-
Type
-
void
(static) toBeNaN() → {void}
- Source:
Checks whether a received value is NaN.
Example
describe('Example toBeNaN Test', function () {
test('Check a return of the returnNullFunc', function () {
var retVal = returnNullFunc();
expect(retVal).toBeNull();
});
});
Parameters:
Returns:
-
Type
-
void
(static) toBeNull() → {void}
- Source:
Returns:
-
Type
-
void
(static) toBeTruthy() → {void}
- Source:
Returns:
-
Type
-
void
(static) toBeUndefined() → {void}
- Source:
Returns:
-
Type
-
void
(static) toContain(item) → {void}
- Source:
Checks that an item is in an array. For testing the items in the array, this uses ===, a strict equality check. .toContain can also check whether a string is a substring of another string.
Example
test('the flavor list contains lime', function () {
expect(getAllFlavors()).toContain('lime');
// If getAllFlavors() returns ['apple', 'lemon', 'lime'], pass the test.
// If getAllFlavors() returns 'apple lemon lime', pass the test.
});
Parameters:
| Name |
Type |
Description |
item |
string
|
|
Returns:
-
Type
-
void
(static) toContainEqual(item) → {void}
- Source:
Parameters:
| Name |
Type |
Description |
item |
string
|
|
Returns:
-
Type
-
void
(static) toEqual(expected) → {void}
- Source:
Parameters:
| Name |
Type |
Description |
expected |
number
|
|
Returns:
-
Type
-
void
(static) toHaveLength(expected) → {void}
- Source:
Parameters:
| Name |
Type |
Description |
expected |
number
|
|
Returns:
-
Type
-
void
(static) toMatch(regexpObj) → {void}
- Source:
Checks a string matches a regular expression.
Example
// Checks essayOnTheBestFlavor() returns
describe('an essay on the best flavor', function () {
test('mentions grapefruit', function () {
expect(essayOnTheBestFlavor()).toMatch(/grapefruit/);
// or
expect(essayOnTheBestFlavor()).toMatch(new RegExp('grapefruit'));
});
});
Parameters:
| Name |
Type |
Description |
regexpObj |
RegExp
|
|
Returns:
-
Type
-
void
(static) toThrowError() → {void}
- Source:
Use to test that a function throws when it is called.
Example
describe('Example toThrowError Test', function () {
test('fs.copyFileSync argument check', function () {
// @NOTE Enclose the test function with function
expect(function () {
fs.copyFileSync(null);
}).toThrowError();
});
});
Returns:
-
Type
-
void
toThrow() → {void}
- Source:
Returns:
-
Type
-
void