Skip to content

Commit fddf538

Browse files
committed
copy alertForMiscreant into findMiscreant
1 parent 5c6685d commit fddf538

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/miscreant-handling/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@ export function alertForMiscreant(people) {
1515
}
1616
return '';
1717
}
18+
19+
export function findMiscreant(people) {
20+
for (const p of people) {
21+
if (p === 'Don') {
22+
setOffAlarms();
23+
return 'Don';
24+
}
25+
if (p === 'John') {
26+
setOffAlarms();
27+
return 'John';
28+
}
29+
}
30+
return '';
31+
}

src/miscreant-handling/index.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { jest, expect } from '@jest/globals';
2-
import { alertForMiscreant } from './index';
2+
import { alertForMiscreant, findMiscreant } from './index';
33

44
describe('alertForMiscreant', () => {
55
const spy = jest.spyOn(console, 'log');
@@ -24,3 +24,27 @@ describe('alertForMiscreant', () => {
2424
expect(spy).not.toHaveBeenCalled();
2525
});
2626
});
27+
28+
describe('findMiscreant', () => {
29+
const spy = jest.spyOn(console, 'log');
30+
31+
beforeEach(() => spy.mockClear());
32+
33+
it('should set off alarms for Don', () => {
34+
const result = findMiscreant(['Don']);
35+
expect(result).toBe('Don');
36+
expect(spy).toHaveBeenCalledTimes(1);
37+
});
38+
39+
it('should set off alarms for John', () => {
40+
const reuslt = findMiscreant(['John']);
41+
expect(reuslt).toBe('John');
42+
expect(spy).toHaveBeenCalledTimes(1);
43+
});
44+
45+
it('should not set off alarms for other people', () => {
46+
const result = findMiscreant(['Alice']);
47+
expect(result).toBe('');
48+
expect(spy).not.toHaveBeenCalled();
49+
});
50+
});

0 commit comments

Comments
 (0)