Skip to content

Commit af9ba5a

Browse files
committed
blockString-test: extract 'joinLines' util function
1 parent 16afd2e commit af9ba5a

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/language/__tests__/blockString-test.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,27 @@ import { expect } from 'chai';
1111
import { describe, it } from 'mocha';
1212
import { dedentBlockStringValue } from '../blockString';
1313

14+
function joinLines(...args) {
15+
return args.join('\n');
16+
}
17+
1418
describe('dedentBlockStringValue', () => {
1519
it('removes uniform indentation from a string', () => {
16-
const rawValue = [
20+
const rawValue = joinLines(
1721
'',
1822
' Hello,',
1923
' World!',
2024
'',
2125
' Yours,',
2226
' GraphQL.',
23-
].join('\n');
27+
);
2428
expect(dedentBlockStringValue(rawValue)).to.equal(
25-
['Hello,', ' World!', '', 'Yours,', ' GraphQL.'].join('\n'),
29+
joinLines('Hello,', ' World!', '', 'Yours,', ' GraphQL.'),
2630
);
2731
});
2832

2933
it('removes empty leading and trailing lines', () => {
30-
const rawValue = [
34+
const rawValue = joinLines(
3135
'',
3236
'',
3337
' Hello,',
@@ -37,14 +41,14 @@ describe('dedentBlockStringValue', () => {
3741
' GraphQL.',
3842
'',
3943
'',
40-
].join('\n');
44+
);
4145
expect(dedentBlockStringValue(rawValue)).to.equal(
42-
['Hello,', ' World!', '', 'Yours,', ' GraphQL.'].join('\n'),
46+
joinLines('Hello,', ' World!', '', 'Yours,', ' GraphQL.'),
4347
);
4448
});
4549

4650
it('removes blank leading and trailing lines', () => {
47-
const rawValue = [
51+
const rawValue = joinLines(
4852
' ',
4953
' ',
5054
' Hello,',
@@ -54,43 +58,43 @@ describe('dedentBlockStringValue', () => {
5458
' GraphQL.',
5559
' ',
5660
' ',
57-
].join('\n');
61+
);
5862
expect(dedentBlockStringValue(rawValue)).to.equal(
59-
['Hello,', ' World!', '', 'Yours,', ' GraphQL.'].join('\n'),
63+
joinLines('Hello,', ' World!', '', 'Yours,', ' GraphQL.'),
6064
);
6165
});
6266

6367
it('retains indentation from first line', () => {
64-
const rawValue = [
68+
const rawValue = joinLines(
6569
' Hello,',
6670
' World!',
6771
'',
6872
' Yours,',
6973
' GraphQL.',
70-
].join('\n');
74+
);
7175
expect(dedentBlockStringValue(rawValue)).to.equal(
72-
[' Hello,', ' World!', '', 'Yours,', ' GraphQL.'].join('\n'),
76+
joinLines(' Hello,', ' World!', '', 'Yours,', ' GraphQL.'),
7377
);
7478
});
7579

7680
it('does not alter trailing spaces', () => {
77-
const rawValue = [
81+
const rawValue = joinLines(
7882
' ',
7983
' Hello, ',
8084
' World! ',
8185
' ',
8286
' Yours, ',
8387
' GraphQL. ',
8488
' ',
85-
].join('\n');
89+
);
8690
expect(dedentBlockStringValue(rawValue)).to.equal(
87-
[
91+
joinLines(
8892
'Hello, ',
8993
' World! ',
9094
' ',
9195
'Yours, ',
9296
' GraphQL. ',
93-
].join('\n'),
97+
),
9498
);
9599
});
96100
});

0 commit comments

Comments
 (0)