Skip to content

Commit 7a4cbbb

Browse files
committed
suggestionList-test: improve readability
1 parent e38ebb3 commit 7a4cbbb

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/jsutils/__tests__/suggestionList-test.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,50 @@ import { describe, it } from 'mocha';
55

66
import suggestionList from '../suggestionList';
77

8+
function expectSuggestions(input, options) {
9+
return expect(suggestionList(input, options));
10+
}
11+
812
describe('suggestionList', () => {
913
it('Returns results when input is empty', () => {
10-
expect(suggestionList('', ['a'])).to.deep.equal(['a']);
14+
expectSuggestions('', ['a']).to.deep.equal(['a']);
1115
});
1216

1317
it('Returns empty array when there are no options', () => {
14-
expect(suggestionList('input', [])).to.deep.equal([]);
18+
expectSuggestions('input', []).to.deep.equal([]);
1519
});
1620

1721
it('Returns options with small lexical distance', () => {
18-
expect(suggestionList('greenish', ['green'])).to.deep.equal(['green']);
19-
expect(suggestionList('green', ['greenish'])).to.deep.equal(['greenish']);
22+
expectSuggestions('greenish', ['green']).to.deep.equal(['green']);
23+
expectSuggestions('green', ['greenish']).to.deep.equal(['greenish']);
2024
});
2125

2226
it('Returns options with different case', () => {
2327
// cSpell:ignore verylongstring
24-
expect(suggestionList('verylongstring', ['VERYLONGSTRING'])).to.deep.equal([
28+
expectSuggestions('verylongstring', ['VERYLONGSTRING']).to.deep.equal([
2529
'VERYLONGSTRING',
2630
]);
2731

28-
expect(suggestionList('VERYLONGSTRING', ['verylongstring'])).to.deep.equal([
32+
expectSuggestions('VERYLONGSTRING', ['verylongstring']).to.deep.equal([
2933
'verylongstring',
3034
]);
3135

32-
expect(suggestionList('VERYLONGSTRING', ['VeryLongString'])).to.deep.equal([
36+
expectSuggestions('VERYLONGSTRING', ['VeryLongString']).to.deep.equal([
3337
'VeryLongString',
3438
]);
3539
});
3640

3741
it('Returns options with transpositions', () => {
38-
expect(suggestionList('agr', ['arg'])).to.deep.equal(['arg']);
39-
40-
expect(suggestionList('214365879', ['123456789'])).to.deep.equal([
41-
'123456789',
42-
]);
42+
expectSuggestions('agr', ['arg']).to.deep.equal(['arg']);
43+
expectSuggestions('214365879', ['123456789']).to.deep.equal(['123456789']);
4344
});
4445

4546
it('Returns options sorted based on lexical distance', () => {
46-
expect(suggestionList('abc', ['a', 'ab', 'abc'])).to.deep.equal([
47-
'abc',
48-
'ab',
49-
]);
47+
expectSuggestions('abc', ['a', 'ab', 'abc']).to.deep.equal(['abc', 'ab']);
5048
});
5149

5250
it('Returns options with the same lexical distance sorted lexicographically', () => {
53-
expect(suggestionList('a', ['az', 'ax', 'ay'])).to.deep.equal([
51+
expectSuggestions('a', ['az', 'ax', 'ay']).to.deep.equal([
5452
'ax',
5553
'ay',
5654
'az',

0 commit comments

Comments
 (0)