@@ -19,19 +19,43 @@ const tally = require("./tally.js");
1919// Given a function called tally
2020// When passed an array of items
2121// Then it should return an object containing the count for each unique item
22- test . todo ( "tally returns correct counts for unique items in an array" ) ;
22+ test ( "tally returns correct counts for unique items in an array" , ( ) => {
23+ const input = [ "a" , "b" , "c" ] ;
24+ const result = tally ( input ) ;
2325
26+ expect ( result ) . toEqual ( {
27+ a : 1 ,
28+ b : 1 ,
29+ c : 1 ,
30+ } ) ;
31+ } ) ;
2432// Given an empty array
2533// When passed to tally
2634// Then it should return an empty object
27- test . todo ( "tally on an empty array returns an empty object" ) ;
35+ test ( "tally on an empty array returns an empty object" , ( ) => {
36+ const result = tally ( [ ] ) ;
2837
38+ expect ( result ) . toEqual ( { } ) ;
39+ } ) ;
2940// Given an array with duplicate items
3041// When passed to tally
3142// Then it should return counts for each unique item
32- test . todo ( "tally returns correct counts for duplicate items in an array" ) ;
43+ test ( "tally returns correct counts for duplicate items in an array" , ( ) => {
44+ const input = [ "a" , "a" , "b" , "c" ] ;
45+ const result = tally ( input ) ;
46+
47+ expect ( result ) . toEqual ( {
48+ a : 2 ,
49+ b : 1 ,
50+ c : 1
51+ } ) ;
52+ } ) ;
3353
3454// Given an invalid input like a string
3555// When passed to tally
3656// Then it should throw an error
37- test . todo ( "tally with invalid input throws an error" ) ;
57+ test ( "tally with invalid input throws an error" , ( ) => {
58+ expect ( ( ) => tally ( "invalid input" ) ) . toThrow ( ) ;
59+ expect ( ( ) => tally ( 123 ) ) . toThrow ( ) ;
60+ expect ( ( ) => tally ( null ) ) . toThrow ( ) ;
61+ } ) ;
0 commit comments