1
1
import * as helpers from './helpers' ;
2
2
3
+ let originalEnv : any = process . env ;
3
4
describe ( 'helpers' , ( ) => {
5
+
6
+ beforeEach ( ( ) => {
7
+ originalEnv = process . env ;
8
+ process . env = { } ;
9
+ } ) ;
10
+
11
+ afterEach ( ( ) => {
12
+ process . env = originalEnv ;
13
+ } ) ;
14
+
15
+ describe ( 'getIntPropertyValue' , ( ) => {
16
+ it ( 'should return an int' , ( ) => {
17
+ // arrange
18
+ const propertyName = 'test' ;
19
+ const propertyValue = '3000' ;
20
+ process . env [ propertyName ] = propertyValue ;
21
+
22
+ // act
23
+ const result = helpers . getIntPropertyValue ( propertyName ) ;
24
+
25
+ // assert
26
+ expect ( result ) . toEqual ( 3000 ) ;
27
+ } ) ;
28
+
29
+ it ( 'should round to an int' , ( ) => {
30
+ // arrange
31
+ const propertyName = 'test' ;
32
+ const propertyValue = '3000.03' ;
33
+ process . env [ propertyName ] = propertyValue ;
34
+
35
+ // act
36
+ const result = helpers . getIntPropertyValue ( propertyName ) ;
37
+
38
+ // assert
39
+ expect ( result ) . toEqual ( 3000 ) ;
40
+ } ) ;
41
+
42
+ it ( 'should round to a NaN' , ( ) => {
43
+ // arrange
44
+ const propertyName = 'test' ;
45
+ const propertyValue = 'tacos' ;
46
+ process . env [ propertyName ] = propertyValue ;
47
+
48
+ // act
49
+ const result = helpers . getIntPropertyValue ( propertyName ) ;
50
+
51
+ // assert
52
+ expect ( result ) . toEqual ( NaN ) ;
53
+ } ) ;
54
+ } ) ;
55
+
4
56
describe ( 'getBooleanPropertyValue' , ( ) => {
5
57
it ( 'should return true when value is "true"' , ( ) => {
6
58
// arrange
7
59
const propertyName = 'test' ;
8
60
const propertyValue = 'true' ;
9
- let environment : any = { } ;
10
- environment [ propertyName ] = propertyValue ;
11
- process . env = environment ;
61
+ process . env [ propertyName ] = propertyValue ;
12
62
// act
13
63
const result = helpers . getBooleanPropertyValue ( propertyName ) ;
14
64
// assert
@@ -18,8 +68,6 @@ describe('helpers', () => {
18
68
it ( 'should return false when value is undefined/null' , ( ) => {
19
69
// arrange
20
70
const propertyName = 'test' ;
21
- let environment : any = { } ;
22
- process . env = environment ;
23
71
// act
24
72
const result = helpers . getBooleanPropertyValue ( propertyName ) ;
25
73
// assert
@@ -30,9 +78,7 @@ describe('helpers', () => {
30
78
// arrange
31
79
const propertyName = 'test' ;
32
80
const propertyValue = 'taco' ;
33
- let environment : any = { } ;
34
- environment [ propertyName ] = propertyValue ;
35
- process . env = environment ;
81
+ process . env [ propertyName ] = propertyValue ;
36
82
// act
37
83
const result = helpers . getBooleanPropertyValue ( propertyName ) ;
38
84
// assert
0 commit comments