@@ -14,7 +14,22 @@ describe('TopologyDescription (integration tests)', function () {
14
14
await client . close ( ) ;
15
15
} ) ;
16
16
17
+ beforeEach ( async function ( ) {
18
+ client = this . configuration . newClient ( ) ;
19
+ await client . connect ( ) ;
20
+ } ) ;
21
+
17
22
context ( 'options' , function ( ) {
23
+ let client : MongoClient ;
24
+
25
+ afterEach ( async function ( ) {
26
+ await client . close ( ) ;
27
+ } ) ;
28
+
29
+ beforeEach ( async function ( ) {
30
+ client = this . configuration . newClient ( ) ;
31
+ } ) ;
32
+
18
33
context ( 'localThresholdMS' , function ( ) {
19
34
it ( 'should default to 15ms' , async function ( ) {
20
35
const options : MongoClientOptions = { } ;
@@ -35,15 +50,6 @@ describe('TopologyDescription (integration tests)', function () {
35
50
} ) ;
36
51
37
52
context ( 'topology types' , function ( ) {
38
- let client : MongoClient ;
39
- beforeEach ( async function ( ) {
40
- client = this . configuration . newClient ( ) ;
41
- } ) ;
42
-
43
- afterEach ( async function ( ) {
44
- await client . close ( ) ;
45
- } ) ;
46
-
47
53
const topologyTypesMap = new Map < TopologyTypeRequirement , TopologyType > ( [
48
54
[ 'single' , TopologyType . Single ] ,
49
55
[ 'replicaset' , TopologyType . ReplicaSetWithPrimary ] ,
@@ -65,4 +71,23 @@ describe('TopologyDescription (integration tests)', function () {
65
71
) ;
66
72
}
67
73
} ) ;
74
+
75
+ describe ( 'json stringification' , function ( ) {
76
+ it ( 'can be stringified without error' , function ( ) {
77
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
78
+ const description = client . topology ?. description ! ;
79
+ expect ( description ) . to . exist ;
80
+
81
+ expect ( ( ) => JSON . stringify ( description ) ) . not . to . throw ;
82
+ } ) ;
83
+
84
+ it ( 'properly stringifies the server description map' , function ( ) {
85
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
86
+ const description = client . topology ?. description ! ;
87
+ expect ( description ) . to . exist ;
88
+
89
+ const { servers } = JSON . parse ( JSON . stringify ( description ) ) ;
90
+ expect ( Object . keys ( servers ) . length > 0 , '`servers` stringified with no servers.' ) . to . be . true ;
91
+ } ) ;
92
+ } ) ;
68
93
} ) ;
0 commit comments