File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,6 +53,17 @@ export class Text {
5353 return this . content . split ( '\n' ) ;
5454 }
5555
56+ /**
57+ * Returns `true` if the text contains `value`.
58+ *
59+ * @param value The string or RegExp to search for.
60+ */
61+ contains ( value : string | RegExp ) : boolean {
62+ return typeof value === 'string'
63+ ? this . content . includes ( value )
64+ : value . exec ( this . content ) !== null ;
65+ }
66+
5667 /**
5768 * Replace every occurrance of `searchValue` with `replaceValue`.
5869 *
Original file line number Diff line number Diff line change @@ -23,6 +23,32 @@ describe('Text', () => {
2323 } ) ;
2424 } ) ;
2525
26+ describe ( 'contains' , ( ) => {
27+ context ( 'with a string' , ( ) => {
28+ it ( 'should return true if text contains the string' , ( ) => {
29+ const text = new Text ( 'one\ntwo\nthree' ) ;
30+ expect ( text . contains ( 'two' ) ) . to . be . true ;
31+ } ) ;
32+
33+ it ( 'should return false if text contains the string' , ( ) => {
34+ const text = new Text ( 'one\ntwo\nthree' ) ;
35+ expect ( text . contains ( 'blah' ) ) . to . be . false ;
36+ } ) ;
37+ } ) ;
38+
39+ context ( 'with a regex' , ( ) => {
40+ it ( 'should return true if text matches the regex' , ( ) => {
41+ const text = new Text ( 'one\ntwo\nthree' ) ;
42+ expect ( text . contains ( / t w o / ) ) . to . be . true ;
43+ } ) ;
44+
45+ it ( 'should return false if text matches the regex' , ( ) => {
46+ const text = new Text ( 'one\ntwo\nthree' ) ;
47+ expect ( text . contains ( / b l a h / ) ) . to . be . false ;
48+ } ) ;
49+ } ) ;
50+ } ) ;
51+
2652 describe ( 'replaceAll' , ( ) => {
2753 it ( 'should work with a string' , ( ) => {
2854 const text = new Text ( 'one. two. three' ) ;
You can’t perform that action at this time.
0 commit comments