Basic Assertions - dylanparry/ceylon GitHub Wiki
expect(item: any).toExist(message?: string): this;
Asserts that the tested item
is not one of the following:
undefined
null
-
''
(empty string) -
[]
(empty array) -
{}
(empty object)
Outputs an optional message
in case of a failed assertion.
Unlike some other assertion libraries, this will not throw an Assertion Error for:
0
false
NaN
As all these are considered to be existant values.
expect('I am a string').toExist();
expect('').toExist(); // Assertion Error
expect(item: any).toNotExist(message?: string): this;
Asserts that the tested item
is one of the following:
undefined
null
-
''
(empty string) -
[]
(empty array) -
{}
(empty object)
Outputs an optional message
in case of a failed assertion.
Unlike some other assertion libraries, this will throw an Assertion Error for:
0
false
NaN
As all these are considered to be existant values.
expect('').toNotExist();
expect(false).toNotExist(); // Assertion Error
expect(item: T).toBe(value: T, message?: string): this;
Asserts that the tested item
is strictly equal to value
.
Outputs an optional message
in case of a failed assertion.
expect(50 + 50).toBe(100);
expect('I am a string').toBe('I AM A STRING'); // Assertion Error
expect(item: T).toNotBe(value: T, message?: string): this;
Asserts that the tested item
is not strictly equal to value
.
Outputs an optional message
in case of a failed assertion.
expect('I am a string').toNotBe('I AM A STRING');
expect(50 + 50).toNotBe(100); // Assertion Error
expect(item: T).toEqual(value: T, message?: string): this;
Asserts that the tested item
is deep equal to value
. This should be used for testing objects and arrays.
Outputs an optional message
in case of a failed assertion.
expect({ id: 1, name: 'Example' }).toEqual({ id: 1, name: 'Example' });
expect({ id: 1, name: 'Example' }).toEqual({ id: 2, name: 'Example' }); // Assertion Error
expect(item: T).toNotEqual(value: T, message?: string): this;
Asserts that the tested item
is not deep equal to value
. This should be used for testing objects and arrays.
Outputs an optional message
in case of a failed assertion.
expect({ id: 1, name: 'Example' }).toNotEqual({ id: 2, name: 'Example' });
expect({ id: 1, name: 'Example' }).toNotEqual({ id: 1, name: 'Example' }); // Assertion Error
expect(item: T).toBeA(constructor: string, message?: string): this;
Asserts that the type of the tested item
is constructor
.
Outputs an optional message
in case of a failed assertion.
expect(100).toBeA('number');
expect('100').toBeA('number'); // Assertion Error
- toBeAn
expect(item: T).toNotBeA(constructor: string, message?: string): this;
Asserts that the type of the tested item
is not constructor
.
Outputs an optional message
in case of a failed assertion.
expect('100').toNotBeA('number');
expect(100).toNotBeA('number'); // Assertion Error
- toNotBeAn