11import { describe , expect , it } from 'bun:test'
22
3- import { isEmptyObject , sortObject , sortObjectKeys } from './objects'
3+ import { isEmptyObject } from './objects'
44
55describe ( 'isEmptyObject' , ( ) => {
66 it ( 'returns true for an empty object' , ( ) => {
@@ -16,59 +16,3 @@ describe('isEmptyObject', () => {
1616 } )
1717} )
1818
19- describe ( 'sortObjectKeys' , ( ) => {
20- const comparator = sortObjectKeys ( [ 'a' , 'b' , 'c' ] )
21-
22- it ( 'returns 0 when both objects are not in the keys array' , ( ) => {
23- const a = { d : 1 }
24- const b = { e : 2 }
25- expect ( comparator ( a , b ) ) . toBe ( 0 )
26- } )
27-
28- it ( 'returns 1 when only the first object is not in the keys array' , ( ) => {
29- const a = { d : 1 }
30- const b = { a : 2 }
31- expect ( comparator ( a , b ) ) . toBe ( 1 )
32- } )
33-
34- it ( 'returns -1 when only the second object is not in the keys array' , ( ) => {
35- const a = { b : 1 }
36- const b = { d : 2 }
37- expect ( comparator ( a , b ) ) . toBe ( - 1 )
38- } )
39-
40- it ( 'returns a negative number when the first object is before the second object in the keys array' , ( ) => {
41- const a = { b : 1 }
42- const b = { c : 2 }
43- expect ( comparator ( a , b ) ) . toBeLessThan ( 0 )
44- } )
45-
46- it ( 'returns a positive number when the first object is after the second object in the keys array' , ( ) => {
47- const a = { c : 1 }
48- const b = { b : 2 }
49- expect ( comparator ( a , b ) ) . toBeGreaterThan ( 0 )
50- } )
51-
52- it ( 'returns 0 when both objects are in the same position in the keys array' , ( ) => {
53- const a = { b : 1 }
54- const b = { b : 2 }
55- expect ( comparator ( a , b ) ) . toBe ( 0 )
56- } )
57- } )
58-
59- describe ( 'sortObject' , ( ) => {
60- it ( 'sorts the keys of an object in alphabetical order' , ( ) => {
61- const obj = { b : 2 , a : 1 , c : 3 }
62- const sortedObj = sortObject ( obj )
63-
64- expect ( sortedObj ) . toEqual ( { a : 1 , b : 2 , c : 3 } )
65- } )
66-
67- it ( 'sorts the keys of an object using a custom comparator function' , ( ) => {
68- const obj = { b : 2 , a : 1 , c : 3 }
69- const comparator = sortObjectKeys ( [ 'c' , 'b' , 'a' ] ) as ( a : unknown , b : unknown ) => number
70- const sortedObj = sortObject ( obj , comparator )
71-
72- expect ( sortedObj ) . toEqual ( { c : 3 , b : 2 , a : 1 } )
73- } )
74- } )
0 commit comments