File tree 3 files changed +22
-19
lines changed
3 files changed +22
-19
lines changed Original file line number Diff line number Diff line change @@ -9,15 +9,5 @@ const jokesAPI = async (numOfJokes) => {
9
9
) ;
10
10
return response ;
11
11
} ;
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 ;
Original file line number Diff line number Diff line change 1
1
import dotenv from 'dotenv' ;
2
2
import fetchCocktail from './components/cocktail.js' ;
3
- import fetchJokes from './components/jokes.js' ;
3
+ import jokesAPI from './components/jokes.js' ;
4
4
import promptSync from 'prompt-sync' ;
5
5
const prompt = promptSync ( ) ;
6
6
dotenv . config ( ) ;
7
7
8
8
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
+ } ) ;
10
18
fetchCocktail ( prompt ( 'Enter cocktail name: ' ) ) ;
Original file line number Diff line number Diff line change 1
- import fetchJokes from '../index .js' ;
1
+ import jokesAPI from '../components/jokes .js' ;
2
2
import { expect } from 'chai' ;
3
3
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
+ } ) ;
8
13
} ) ;
9
14
} ) ;
You can’t perform that action at this time.
0 commit comments