getSuggestion-test.js
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* eslint-env jest */
import assert from 'assert';
import getSuggestion from '../../../src/util/getSuggestion';
describe('spell check suggestion API', () => {
it('should return no suggestions given empty word and no dictionary', () => {
const word = '';
const expected = [];
const actual = getSuggestion(word);
assert.deepEqual(expected, actual);
});
it('should return no suggestions given real word and no dictionary', () => {
const word = 'foo';
const expected = [];
const actual = getSuggestion(word);
assert.deepEqual(expected, actual);
});
it('should return correct suggestion given real word and a dictionary', () => {
const word = 'fo';
const dictionary = ['foo', 'bar', 'baz'];
const expected = ['foo'];
const actual = getSuggestion(word, dictionary);
assert.deepEqual(expected, actual);
});
it('should return multiple correct suggestions given real word and a dictionary', () => {
const word = 'theer';
const dictionary = ['there', 'their', 'foo', 'bar'];
const expected = ['there', 'their'];
const actual = getSuggestion(word, dictionary);
assert.deepEqual(expected, actual);
});
it('should return correct # of suggestions given the limit argument', () => {
const word = 'theer';
const dictionary = ['there', 'their', 'foo', 'bar'];
const limit = 1;
const expected = 1;
const actual = getSuggestion(word, dictionary, limit).length;
assert.deepEqual(expected, actual);
});
});