-
Notifications
You must be signed in to change notification settings - Fork 1
String Assertions
Dylan Parry edited this page Oct 5, 2016
·
10 revisions
expect(item: string).toMatch(pattern: RegExp, message?: string): this;
Asserts that the string item
matches the regular expression pattern
.
Outputs an optional message
in case of a failed assertion.
expect('I am a string').toMatch(/^.*string$/);
expect('I am a string').toMatch(/^.*number$/); // Assertion Error
expect(item: string).toNotMatch(pattern: RegExp, message?: string): this;
Asserts that the string item
does not match the regular expression pattern
.
Outputs an optional message
in case of a failed assertion.
expect('I am a string').toNotMatch(/^.*number$/);
expect('I am a string').toNotMatch(/^.*string$/); // Assertion Error
expect(item: string).toInclude(value: string, message?: string): this;
Asserts that the string item
contains the string value
.
Outputs an optional message
in case of a failed assertion.
expect('I am a string').toInclude('am');
expect('I am a string').toInclude('not'); // Assertion Error
- toContain
expect(item: string).toExclude(value: string, message?: string): this;
Asserts that the string item
does not include the string value
.
Outputs an optional message
in case of a failed assertion.
expect('I am a string').toExclude('not');
expect('I am a string').toExclude('am'); // Assertion Error
- toNotInclude
- toNotContain
expect(item: string).toHaveLength(value: number, message?: string): this;
Asserts that the length of the string item
is equal to value
.
expect('I am a string!').toHaveLength(14);
expect('I am a string!').toHaveLength(10); // Assertion Error