Skip to content

Commit 14cfdae

Browse files
authored
chore: simpler string trimming (#14798)
1 parent eef69ea commit 14cfdae

File tree

41 files changed

+60
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+60
-75
lines changed

.eslintrc.cjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,9 +712,6 @@ module.exports = {
712712
'unicorn/prefer-set-has': 'off',
713713
'unicorn/prefer-spread': 'off',
714714
'unicorn/prefer-string-replace-all': 'off',
715-
'unicorn/prefer-string-slice': 'off',
716-
'unicorn/prefer-string-starts-ends-with': 'off',
717-
'unicorn/prefer-string-trim-start-end': 'off',
718715
'unicorn/prefer-type-error': 'off',
719716
'unicorn/prevent-abbreviations': 'off',
720717
'unicorn/text-encoding-identifier-case': 'off',

docs/ExpectAPI.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ expect.extend({
16421642
toMatchTrimmedSnapshot(received, length) {
16431643
return toMatchSnapshot.call(
16441644
this,
1645-
received.substring(0, length),
1645+
received.slice(0, length),
16461646
'toMatchTrimmedSnapshot',
16471647
);
16481648
},
@@ -1666,7 +1666,7 @@ const {toMatchInlineSnapshot} = require('jest-snapshot');
16661666

16671667
expect.extend({
16681668
toMatchTrimmedInlineSnapshot(received, ...rest) {
1669-
return toMatchInlineSnapshot.call(this, received.substring(0, 10), ...rest);
1669+
return toMatchInlineSnapshot.call(this, received.slice(0, 10), ...rest);
16701670
},
16711671
});
16721672

docs/TutorialAsync.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const users = {
4646

4747
export default function request(url) {
4848
return new Promise((resolve, reject) => {
49-
const userID = parseInt(url.substr('/users/'.length), 10);
49+
const userID = parseInt(url.slice('/users/'.length), 10);
5050
process.nextTick(() =>
5151
users[userID]
5252
? resolve(users[userID])

e2e/Utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ const sortTests = (stdout: string) =>
273273
}, [])
274274
.sort(([a], [b]) => (a > b ? 1 : -1))
275275
.map(strings =>
276-
strings.length > 1 ? `${strings.join('\n').trimRight()}\n` : strings[0],
276+
strings.length > 1 ? `${strings.join('\n').trimEnd()}\n` : strings[0],
277277
)
278278
.join('\n')
279279
.trim();

e2e/__tests__/each.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('shows the correct errors in stderr when failing tests', () => {
2828
expect(result.exitCode).toBe(1);
2929
const output = extractSummary(result.stderr)
3030
.rest.split('\n')
31-
.map(line => line.trimRight())
31+
.map(line => line.trimEnd())
3232
.join('\n');
3333
expect(output).toMatchSnapshot();
3434
});

e2e/__tests__/failures.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,15 @@ test('works with snapshot failures', () => {
7878

7979
const result = normalizeDots(cleanStderr(stderr));
8080

81-
expect(
82-
result.substring(0, result.indexOf('Snapshot Summary')),
83-
).toMatchSnapshot();
81+
expect(result.slice(0, result.indexOf('Snapshot Summary'))).toMatchSnapshot();
8482
});
8583

8684
test('works with snapshot failures with hint', () => {
8785
const {stderr} = runJest(dir, ['snapshotWithHint.test.js']);
8886

8987
const result = normalizeDots(cleanStderr(stderr));
9088

91-
expect(
92-
result.substring(0, result.indexOf('Snapshot Summary')),
93-
).toMatchSnapshot();
89+
expect(result.slice(0, result.indexOf('Snapshot Summary'))).toMatchSnapshot();
9490
});
9591

9692
test('works with error with cause', () => {
@@ -113,7 +109,7 @@ test('works with error with cause thrown outside tests', () => {
113109
expect(
114110
// jasmine runner differ from circus one in this case, we just start
115111
// the comparison when the stack starts to be reported
116-
sanitizedSummary.substring(sanitizedSummary.indexOf('error during f')),
112+
sanitizedSummary.slice(sanitizedSummary.indexOf('error during f')),
117113
).toMatchSnapshot();
118114
});
119115

examples/async/__mocks__/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const users = {
99

1010
export default function request(url) {
1111
return new Promise((resolve, reject) => {
12-
const userID = parseInt(url.substr('/users/'.length), 10);
12+
const userID = parseInt(url.slice('/users/'.length), 10);
1313
process.nextTick(() =>
1414
users[userID]
1515
? resolve(users[userID])

packages/babel-jest/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function getCacheKeyFromConfig(
9999
.update('\0', 'utf8')
100100
.update(process.version)
101101
.digest('hex')
102-
.substring(0, 32);
102+
.slice(0, 32);
103103
}
104104

105105
function loadBabelConfig(

packages/create-jest/src/__tests__/init.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ describe('init', () => {
205205
});
206206
});
207207

208-
describe.each(JEST_CONFIG_EXT_ORDER.map(e => e.substring(1)))(
208+
describe.each(JEST_CONFIG_EXT_ORDER.map(e => e.slice(1)))(
209209
'has-jest-config-file-%s',
210210
extension => {
211211
describe('ask the user whether to override config or not', () => {

packages/jest-cli/src/__tests__/args.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('check', () => {
6565
expect(() => check(argv({maxWorkers: '50%'}))).not.toThrow();
6666
});
6767

68-
test.each(constants.JEST_CONFIG_EXT_ORDER.map(e => e.substring(1)))(
68+
test.each(constants.JEST_CONFIG_EXT_ORDER.map(e => e.slice(1)))(
6969
'allows using "%s" file for --config option',
7070
ext => {
7171
expect(() => check(argv({config: `jest.config.${ext}`}))).not.toThrow();

0 commit comments

Comments
 (0)