Skip to content

Commit bfc6467

Browse files
committed
fix: fix automated testing
1 parent b20c024 commit bfc6467

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

components/jokes.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,5 @@ const jokesAPI = async (numOfJokes) => {
99
);
1010
return response;
1111
};
12-
const fetchJokes = async (numOfJokes) => {
13-
jokesAPI(numOfJokes)
14-
.then((res) => {
15-
res.data.forEach((joke, index) => {
16-
console.log(`${index + 1}. ${joke.joke}`);
17-
});
18-
})
19-
.catch((err) => {
20-
console.log(err);
21-
});
22-
};
23-
export default fetchJokes;
12+
13+
export default jokesAPI;

index.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import dotenv from 'dotenv';
22
import fetchCocktail from './components/cocktail.js';
3-
import fetchJokes from './components/jokes.js';
3+
import jokesAPI from './components/jokes.js';
44
import promptSync from 'prompt-sync';
55
const prompt = promptSync();
66
dotenv.config();
77

88
console.log('CHUC NAM MOI THANH CONG');
9-
fetchJokes(prompt('Enter number of jokes: '));
9+
jokesAPI(prompt('Enter number of jokes: '))
10+
.then((res) => {
11+
res.data.forEach((joke, index) => {
12+
console.log(`${index + 1}. ${joke.joke}`);
13+
});
14+
})
15+
.catch((error) => {
16+
console.log(error);
17+
});
1018
fetchCocktail(prompt('Enter cocktail name: '));

test/check-output.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import fetchJokes from '../index.js';
1+
import jokesAPI from '../components/jokes.js';
22
import { expect } from 'chai';
33

4-
describe('fetchJokes', () => {
5-
it('should fetch jokes', async () => {
6-
const response = await fetchJokes();
7-
expect(response.status).to.equal(200);
4+
describe('JOKES API', () => {
5+
it('should return array of jokes', async () => {
6+
await jokesAPI(3)
7+
.then((res) => {
8+
expect(res.data).to.be.an('array');
9+
})
10+
.catch((err) => {
11+
console.log(err);
12+
});
813
});
914
});

0 commit comments

Comments
 (0)