File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ const invert = require ( "./invert.js" ) ;
2+
3+ // Given an object
4+ // When invert is passed this object
5+ // Then it should swap the keys and values
6+ test ( "invert swaps the keys and values of an object" , ( ) => {
7+ expect ( invert ( { x : 10 , y : 20 } ) ) . toEqual ( {
8+ 10 : "x" ,
9+ 20 : "y" ,
10+ } ) ;
11+ } ) ;
12+
13+ // Given an object with one key value pair
14+ // When passed to invert
15+ // Then it should return the swapped pair
16+ test ( "invert swaps a single key value pair" , ( ) => {
17+ expect ( invert ( { a : 1 } ) ) . toEqual ( {
18+ 1 : "a" ,
19+ } ) ;
20+ } ) ;
21+
22+ // Given an empty object
23+ // When passed to invert
24+ // Then it should return an empty object
25+ test ( "invert on an empty object returns an empty object" , ( ) => {
26+ expect ( invert ( { } ) ) . toEqual ( { } ) ;
27+ } ) ;
28+
29+ // Given an invalid input like an array
30+ // When passed to invert
31+ // Then it should throw an error
32+ test ( "invert throws an error for invalid input" , ( ) => {
33+ expect ( ( ) => invert ( [ ] ) ) . toThrow ( "Input must be an object" ) ;
34+ } ) ;
You can’t perform that action at this time.
0 commit comments