@@ -19,16 +19,32 @@ 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+ describe ( "tally()" , ( ) => {
23+ // Given an array with duplicate items
24+ // When passed to tally
25+ // Then it should return counts for each unique item
26+ describe ( "when given an array with duplicate items" , ( ) => {
27+ test ( "should return an object with counts for each unique item" , ( ) => {
28+ expect ( tally ( [ "a" ] ) ) . toEqual ( { a : 1 } ) ;
29+ expect ( tally ( [ "a" , "a" , "a" ] ) ) . toEqual ( { a : 3 } ) ;
30+ expect ( tally ( [ "a" , "a" , "b" , "c" ] ) ) . toEqual ( { a : 2 , b : 1 , c : 1 } ) ;
31+ } ) ;
32+ } ) ;
33+ // Given an empty array
34+ // When passed to tally
35+ // Then it should return an empty object
36+ describe ( "when given an empty array" , ( ) => {
37+ test ( "should return an empty object" , ( ) => {
38+ expect ( tally ( [ ] ) ) . toEqual ( { } ) ;
39+ } ) ;
40+ } ) ;
2241
23- // Given an empty array
24- // When passed to tally
25- // Then it should return an empty object
26- test . todo ( "tally on an empty array returns an empty object" ) ;
27-
28- // Given an array with duplicate items
29- // When passed to tally
30- // Then it should return counts for each unique item
31-
32- // Given an invalid input like a string
33- // When passed to tally
34- // Then it should throw an error
42+ // Given an invalid input like a string
43+ // When passed to tally
44+ // Then it should throw an error
45+ describe ( "when given invalid input such as a string" , ( ) => {
46+ test ( "should throw an error" , ( ) => {
47+ expect ( ( ) => tally ( "apple" ) ) . toThrow ( "Input should be an array" ) ;
48+ } ) ;
49+ } ) ;
50+ } ) ;
0 commit comments