1import { joinWithCommasAnd } from '../strings'; 2 3describe(joinWithCommasAnd, () => { 4 it(`joins 3+ items with an oxford comma`, () => { 5 expect(joinWithCommasAnd(['a', 'b', 'c'])).toEqual('a, b, and c'); 6 }); 7 8 it(`joins 2 items with an 'and'`, () => { 9 expect(joinWithCommasAnd(['a', 'b'])).toEqual('a and b'); 10 }); 11 12 it(`returns a single item`, () => { 13 expect(joinWithCommasAnd(['a'])).toEqual('a'); 14 }); 15 16 it(`returns an empty string for zero items`, () => { 17 expect(joinWithCommasAnd([])).toEqual(''); 18 }); 19 20 it(`joins limit+1 with 'and 1 other'`, () => { 21 expect(joinWithCommasAnd(['a', 'b', 'c', 'd', 'e'], 4)).toEqual('a, b, c, d, and 1 other'); 22 }); 23 24 it(`joins limit+1 with 'and 1 other'`, () => { 25 expect(joinWithCommasAnd(['a', 'b', 'c', 'd', 'e'], 4)).toEqual('a, b, c, d, and 1 other'); 26 }); 27 28 it(`joins limit+2 or more with 'and x others'`, () => { 29 expect(joinWithCommasAnd(['a', 'b', 'c', 'd', 'e', 'f'], 4)).toEqual( 30 'a, b, c, d, and 2 others' 31 ); 32 }); 33 34 it(`eliminates duplicates`, () => { 35 expect(joinWithCommasAnd(['a', 'c', 'b', 'c'])).toEqual('a, c, and b'); 36 }); 37}); 38