How to use split method in Playwright Internal

Best JavaScript code snippet using playwright-internal

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

s-string.js

Source: s-string.js Github

copy
1describe('String', function() {
2    "use strict";
3    describe("trim", function() {
4        var test = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFFHello, World!\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF";
5
6        it('trims all ES5 whitespace', function() {
7            expect(test.trim()).toEqual("Hello, World!");
8            expect(test.trim().length).toEqual(13);
9        });
10    });
11
12    describe("split", function() {
13        var test = "ab";
14
15        it('If "separator" is undefined must return Array with one String - "this" string', function() {
16            expect(test.split()).toEqual([test]);
17            expect(test.split(void 0)).toEqual([test]);
18        });
19
20        it('If "separator" is undefined and "limit" set to 0 must return Array[]', function() {
21            expect(test.split(void 0, 0)).toEqual([]);
22        });
23
24        describe('Tests from Steven Levithan', function () {
25            it("''.split() results in ['']", function () {
26                expect(''.split()).toEqual(['']);
27            });
28            it("''.split(/./) results in ['']", function () {
29                expect(''.split(/./)).toEqual(['']);
30            });
31            it("''.split(/.?/) results in []", function () {
32                expect(''.split(/.?/)).toEqual([]);
33            });
34            it("''.split(/.??/) results in []", function () {
35                expect(''.split(/.??/)).toEqual([]);
36            });
37            it("'ab'.split(/a*/) results in ['', 'b']", function () {
38                expect('ab'.split(/a*/)).toEqual(['', 'b']);
39            });
40            it("'ab'.split(/a*?/) results in ['a', 'b']", function () {
41                expect('ab'.split(/a*?/)).toEqual(['a', 'b']);
42            });
43            it("'ab'.split(/(?:ab)/) results in ['', '']", function () {
44                expect('ab'.split(/(?:ab)/)).toEqual(['', '']);
45            });
46            it("'ab'.split(/(?:ab)*/) results in ['', '']", function () {
47                expect('ab'.split(/(?:ab)*/)).toEqual(['', '']);
48            });
49            it("'ab'.split(/(?:ab)*?/) results in ['a', 'b']", function () {
50                expect('ab'.split(/(?:ab)*?/)).toEqual(['a', 'b']);
51            });
52            it("'test'.split('') results in ['t', 'e', 's', 't']", function () {
53                expect('test'.split('')).toEqual(['t', 'e', 's', 't']);
54            });
55            it("'test'.split() results in ['test']", function () {
56                expect('test'.split()).toEqual(['test']);
57            });
58            it("'111'.split(1) results in ['', '', '', '']", function () {
59                expect('111'.split(1)).toEqual(['', '', '', '']);
60            });
61            it("'test'.split(/(?:)/, 2) results in ['t', 'e']", function () {
62                expect('test'.split(/(?:)/, 2)).toEqual(['t', 'e']);
63            });
64            it("'test'.split(/(?:)/, -1) results in ['t', 'e', 's', 't']", function () {
65                expect('test'.split(/(?:)/, -1)).toEqual(['t', 'e', 's', 't']);
66            });
67            it("'test'.split(/(?:)/, undefined) results in ['t', 'e', 's', 't']", function () {
68                expect('test'.split(/(?:)/, undefined)).toEqual(['t', 'e', 's', 't']);
69            });
70            it("'test'.split(/(?:)/, null) results in []", function () {
71                expect('test'.split(/(?:)/, null)).toEqual([]);
72            });
73            it("'test'.split(/(?:)/, NaN) results in []", function () {
74                expect('test'.split(/(?:)/, NaN)).toEqual([]);
75            });
76            it("'test'.split(/(?:)/, true) results in ['t']", function () {
77                expect('test'.split(/(?:)/, true)).toEqual(['t']);
78            });
79            it("'test'.split(/(?:)/, '2') results in ['t', 'e']", function () {
80                expect('test'.split(/(?:)/, '2')).toEqual(['t', 'e']);
81            });
82            it("'test'.split(/(?:)/, 'two') results in []", function () {
83                expect('test'.split(/(?:)/, 'two')).toEqual([]);
84            });
85            it("'a'.split(/-/) results in ['a']", function () {
86                expect('a'.split(/-/)).toEqual(['a']);
87            });
88            it("'a'.split(/-?/) results in ['a']", function () {
89                expect('a'.split(/-?/)).toEqual(['a']);
90            });
91            it("'a'.split(/-??/) results in ['a']", function () {
92                expect('a'.split(/-??/)).toEqual(['a']);
93            });
94            it("'a'.split(/a/) results in ['', '']", function () {
95                expect('a'.split(/a/)).toEqual(['', '']);
96            });
97            it("'a'.split(/a?/) results in ['', '']", function () {
98                expect('a'.split(/a?/)).toEqual(['', '']);
99            });
100            it("'a'.split(/a??/) results in ['a']", function () {
101                expect('a'.split(/a??/)).toEqual(['a']);
102            });
103            it("'ab'.split(/-/) results in ['ab']", function () {
104                expect('ab'.split(/-/)).toEqual(['ab']);
105            });
106            it("'ab'.split(/-?/) results in ['a', 'b']", function () {
107                expect('ab'.split(/-?/)).toEqual(['a', 'b']);
108            });
109            it("'ab'.split(/-??/) results in ['a', 'b']", function () {
110                expect('ab'.split(/-??/)).toEqual(['a', 'b']);
111            });
112            it("'a-b'.split(/-/) results in ['a', 'b']", function () {
113                expect('a-b'.split(/-/)).toEqual(['a', 'b']);
114            });
115            it("'a-b'.split(/-?/) results in ['a', 'b']", function () {
116                expect('a-b'.split(/-?/)).toEqual(['a', 'b']);
117            });
118            it("'a-b'.split(/-??/) results in ['a', '-', 'b']", function () {
119                expect('a-b'.split(/-??/)).toEqual(['a', '-', 'b']);
120            });
121            it("'a--b'.split(/-/) results in ['a', '', 'b']", function () {
122                expect('a--b'.split(/-/)).toEqual(['a', '', 'b']);
123            });
124            it("'a--b'.split(/-?/) results in ['a', '', 'b']", function () {
125                expect('a--b'.split(/-?/)).toEqual(['a', '', 'b']);
126            });
127            it("'a--b'.split(/-??/) results in ['a', '-', '-', 'b']", function () {
128                expect('a--b'.split(/-??/)).toEqual(['a', '-', '-', 'b']);
129            });
130            it("''.split(/()()/) results in []", function () {
131                expect(''.split(/()()/)).toEqual([]);
132            });
133            it("'.'.split(/()()/) results in ['.']", function () {
134                expect('.'.split(/()()/)).toEqual(['.']);
135            });
136            it("'.'.split(/(.?)(.?)/) results in ['', '.', '', '']", function () {
137                expect('.'.split(/(.?)(.?)/)).toEqual(['', '.', '', '']);
138            });
139            it("'.'.split(/(.??)(.??)/) results in ['.']", function () {
140                expect('.'.split(/(.??)(.??)/)).toEqual(['.']);
141            });
142            it("'.'.split(/(.)?(.)?/) results in ['', '.', undefined, '']", function () {
143                expect('.'.split(/(.)?(.)?/)).toEqual(['', '.', undefined, '']);
144            });
145            it("'A<B>bold</B>and<CODE>coded</CODE>'.split(/<(\\/)?([^<>]+)>/) results in ['A', undefined, 'B', 'bold', '/', 'B', 'and', undefined, 'CODE', 'coded', '/', 'CODE', '']", function () {
146                expect('A<B>bold</B>and<CODE>coded</CODE>'.split(/<(\/)?([^<>]+)>/)).toEqual(['A', undefined, 'B', 'bold', '/', 'B', 'and', undefined, 'CODE', 'coded', '/', 'CODE', '']);
147            });
148            it("'tesst'.split(/(s)*/) results in ['t', undefined, 'e', 's', 't']", function () {
149                expect('tesst'.split(/(s)*/)).toEqual(['t', undefined, 'e', 's', 't']);
150            });
151            it("'tesst'.split(/(s)*?/) results in ['t', undefined, 'e', undefined, 's', undefined, 's', undefined, 't']", function () {
152                expect('tesst'.split(/(s)*?/)).toEqual(['t', undefined, 'e', undefined, 's', undefined, 's', undefined, 't']);
153            });
154            it("'tesst'.split(/(s*)/) results in ['t', '', 'e', 'ss', 't']", function () {
155                expect('tesst'.split(/(s*)/)).toEqual(['t', '', 'e', 'ss', 't']);
156            });
157            it("'tesst'.split(/(s*?)/) results in ['t', '', 'e', '', 's', '', 's', '', 't']", function () {
158                expect('tesst'.split(/(s*?)/)).toEqual(['t', '', 'e', '', 's', '', 's', '', 't']);
159            });
160            it("'tesst'.split(/(?:s)*/) results in ['t', 'e', 't']", function () {
161                expect('tesst'.split(/(?:s)*/)).toEqual(['t', 'e', 't']);
162            });
163            it("'tesst'.split(/(?=s+)/) results in ['te', 's', 'st']", function () {
164                expect('tesst'.split(/(?=s+)/)).toEqual(['te', 's', 'st']);
165            });
166            it("'test'.split('t') results in ['', 'es', '']", function () {
167                expect('test'.split('t')).toEqual(['', 'es', '']);
168            });
169            it("'test'.split('es') results in ['t', 't']", function () {
170                expect('test'.split('es')).toEqual(['t', 't']);
171            });
172            it("'test'.split(/t/) results in ['', 'es', '']", function () {
173                expect('test'.split(/t/)).toEqual(['', 'es', '']);
174            });
175            it("'test'.split(/es/) results in ['t', 't']", function () {
176                expect('test'.split(/es/)).toEqual(['t', 't']);
177            });
178            it("'test'.split(/(t)/) results in ['', 't', 'es', 't', '']", function () {
179                expect('test'.split(/(t)/)).toEqual(['', 't', 'es', 't', '']);
180            });
181            it("'test'.split(/(es)/) results in ['t', 'es', 't']", function () {
182                expect('test'.split(/(es)/)).toEqual(['t', 'es', 't']);
183            });
184            it("'test'.split(/(t)(e)(s)(t)/) results in ['', 't', 'e', 's', 't', '']", function () {
185                expect('test'.split(/(t)(e)(s)(t)/)).toEqual(['', 't', 'e', 's', 't', '']);
186            });
187            it("'.'.split(/(((.((.??)))))/) results in ['', '.', '.', '.', '', '', '']", function () {
188                expect('.'.split(/(((.((.??)))))/)).toEqual(['', '.', '.', '.', '', '', '']);
189            });
190            it("'.'.split(/(((((.??)))))/) results in ['.']", function () {
191                expect('.'.split(/(((((.??)))))/)).toEqual(['.']);
192            });
193            it("'a b c d'.split(/ /, -(Math.pow(2, 32) - 1)) results in ['a']", function () {
194                expect('a b c d'.split(/ /, -(Math.pow(2, 32) - 1))).toEqual(['a']);
195            });
196            it("'a b c d'.split(/ /, Math.pow(2, 32) + 1) results in ['a']", function () {
197                expect('a b c d'.split(/ /, Math.pow(2, 32) + 1)).toEqual(['a']);
198            });
199            it("'a b c d'.split(/ /, Infinity) results in []", function () {
200                expect('a b c d'.split(/ /, Infinity)).toEqual([]);
201            });
202        });
203    });
204});
205
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Playwright Internal on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)