@@ -4,6 +4,8 @@ import { AppError, metricsExporter } from '../error-handling';
4
4
import logger from '../libraries/logger' ;
5
5
import { testSetup } from './setup/test-file-setup' ;
6
6
7
+ let processExitStub : sinon . SinonStub ;
8
+
7
9
beforeAll ( async ( ) => {
8
10
await testSetup . start ( {
9
11
startAPI : true ,
@@ -16,7 +18,7 @@ beforeAll(async () => {
16
18
17
19
beforeEach ( ( ) => {
18
20
testSetup . resetBeforeEach ( ) ;
19
- sinon . stub ( process , 'exit' ) ;
21
+ processExitStub = sinon . stub ( process , 'exit' ) ;
20
22
} ) ;
21
23
22
24
afterAll ( async ( ) => {
@@ -87,7 +89,7 @@ describe('Error Handling', () => {
87
89
productId : 2 ,
88
90
mode : 'approved' ,
89
91
} ;
90
- sinon . restore ( ) ;
92
+ processExitStub . restore ( ) ;
91
93
const processExitListener = sinon . stub ( process , 'exit' ) ;
92
94
const errorToThrow = new AppError (
93
95
'saving-failed' ,
@@ -111,7 +113,7 @@ describe('Error Handling', () => {
111
113
productId : 2 ,
112
114
mode : 'approved' ,
113
115
} ;
114
- sinon . restore ( ) ;
116
+ processExitStub . restore ( ) ;
115
117
const processExitListener = sinon . stub ( process , 'exit' ) ;
116
118
// Arbitrarily choose an object that throws an error
117
119
const errorToThrow = new Error ( 'Something vague and unknown' ) ;
@@ -129,14 +131,15 @@ describe('Error Handling', () => {
129
131
//Arrange
130
132
const loggerDouble = sinon . stub ( logger , 'error' ) ;
131
133
const errorToThrow = new Error ( 'An error that wont be caught 😳' ) ;
134
+ processExitStub . restore ( ) ;
132
135
const processExitListener = sinon . stub ( process , 'exit' ) ;
133
136
134
137
//Act
135
138
process . emit ( 'uncaughtException' , errorToThrow ) ;
136
139
137
140
// Assert
138
141
expect ( loggerDouble . lastCall . firstArg ) . toMatchObject ( errorToThrow ) ;
139
- expect ( processExitListener . called ) . toBe ( true ) ;
142
+ expect ( processExitListener . called ) . toBe ( false ) ;
140
143
} ) ;
141
144
142
145
test . todo (
0 commit comments