forked from HackYourFuture/Assignments
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathex3-lemonAllergy.js
More file actions
36 lines (22 loc) · 1022 Bytes
/
ex3-lemonAllergy.js
File metadata and controls
36 lines (22 loc) · 1022 Bytes
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
const sanitizeFruitBasket = require('./ex3-lemonAllergy');
describe('js-wk3-ex3-lemonAllergy', () => {
const fruitBasket = ['apple', 'banana', 'lemon', 'pear'];
const originalFruitBasketContents = [...fruitBasket];
test('sanitizeFruitBasket should take two parameters', () => {
expect(sanitizeFruitBasket.length === 2).toBe(true);
});
test('sanitizeFruitBasket should not modify the original fruitBasket array', () => {
sanitizeFruitBasket(fruitBasket, 'lemon');
const sameContent =
fruitBasket.length === originalFruitBasketContents.length &&
fruitBasket.every((x, i) => x === originalFruitBasketContents[i]);
expect(sameContent).toBe(true);
});
test('sanitizeFruitBasket should return a new array that does not include the unwanted "lemon"', () => {
const result = sanitizeFruitBasket(fruitBasket, 'lemon');
const hasNoLemon = !result
.map(x => String(x).toLowerCase().trim())
.includes('lemon');
expect(hasNoLemon).toBe(true);
});
});