Skip to content

Commit 2854f54

Browse files
refactor(TestingToBeMatchers): add stringOfLengthBetween() and update functionality of stringOfLength().
1 parent 794442c commit 2854f54

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

src/lib/testing-tobe-matchers.class.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,21 +535,44 @@ export class TestingToBeMatchers extends TestingExpect {
535535
return this;
536536
}
537537

538+
/**
539+
* Expects provided value to be a `string` type or an instance of a `String` of the specified length. The method uses `isStringLength()`
540+
* function from the `@angular-package/type`.
541+
* @param value The value of any type that is checked against a `string` type or an instance of a `String` of the specified `length` and
542+
* the result of its check is passed to the `expect()` function of jasmine.
543+
* @param length The length of generic type variable `Length` for the given `value`,
544+
* @param expected The expected `value` of a `boolean` to compare against the result of the `value` check that is passed to the `toBe()`
545+
* method of `jasmine.Matchers`.
546+
* @param expectationFailOutput An additional message when the matcher fails, by default, states the value should be (or not) a `string`
547+
* type or an instance of a `String` of the specified `length`.
548+
* @returns The return value is an instance of `TestingToBeMatchers`.
549+
*/
550+
public stringOfLength<Length extends number>(
551+
value: any,
552+
length: Length,
553+
expected: jasmine.Expected<boolean> = true,
554+
expectationFailOutput: any = `${this.expectationFailOutput} ${
555+
this.getNot() === true ? `not` : ``
556+
} be a \`string\` type or an instance of a \`String\` of the \`length\` equal to ${length}`
557+
): this {
558+
this.toBe(is.stringLength(value, length), expected, expectationFailOutput);
559+
return this;
560+
}
561+
538562
/**
539563
* Expects provided value to be a `string` type or an instance of a `String` of the length between the given minimum and maximum. The
540-
* method uses `isStringLength()` function from the `@angular-package/type`.
564+
* method uses `isStringLengthBetween()` function from the `@angular-package/type`.
541565
* @param value The value of any type that is checked against a `string` type or an instance of a `String` of the specified `length` and
542566
* the result of its check is passed to the `expect()` function of jasmine.
543567
* @param min The **minimum** length of generic type variable `Min` of the given `value`.
544568
* @param max The **maximum** length of generic type variable `Max` of the given `value`.
545-
* @param length An `object` of optional minimum and maximum `length` of the given `value`.
546569
* @param expected The expected `value` of a `boolean` to compare against the result of the `value` check that is passed to the `toBe()`
547570
* method of `jasmine.Matchers`.
548571
* @param expectationFailOutput An additional message when the matcher fails, by default, states the value should be (or not) a `string`
549572
* type or an instance of a `String` of the `length` between the given minimum and maximum.
550573
* @returns The return value is an instance of `TestingToBeMatchers`.
551574
*/
552-
public stringOfLength<Min extends number, Max extends number>(
575+
public stringOfLengthBetween<Min extends number, Max extends number>(
553576
value: any,
554577
min: Min,
555578
max: Max,
@@ -559,7 +582,7 @@ export class TestingToBeMatchers extends TestingExpect {
559582
} be a \`string\` type or an instance of a \`String\` of the \`length\` between the given ${min} and ${max}`
560583
): this {
561584
this.toBe(
562-
is.stringLength(value, min, max),
585+
is.stringLengthBetween(value, min, max),
563586
expected,
564587
expectationFailOutput
565588
);

0 commit comments

Comments
 (0)