1
- import { async , inject } from '@angular/core/testing' ;
1
+ import { inject , waitForAsync } from '@angular/core/testing' ;
2
2
3
3
import { ConfigLoader , ConfigService , ConfigStaticLoader } from '../src' ;
4
4
@@ -10,7 +10,7 @@ describe('@ngx-config/core:', () => {
10
10
11
11
testModuleConfig ( {
12
12
provide : ConfigLoader ,
13
- useFactory : configFactory
13
+ useFactory : configFactory ,
14
14
} ) ;
15
15
} ) ;
16
16
@@ -29,68 +29,86 @@ describe('@ngx-config/core:', () => {
29
29
} ) ;
30
30
} ) ) ;
31
31
32
- it ( 'should be able to get setting(s) using `key`' , async (
33
- inject ( [ ConfigService ] , ( config : ConfigService ) => {
34
- config . loader . loadSettings ( ) . then ( ( ) => {
35
- expect ( config . getSettings ( 'system' ) ) . toEqual ( {
36
- applicationName : 'Mighty Mouse' ,
37
- applicationUrl : 'http://localhost:8000'
38
- } ) ;
32
+ it (
33
+ 'should be able to get setting(s) using `key`' ,
34
+ waitForAsync (
35
+ inject ( [ ConfigService ] , ( config : ConfigService ) => {
36
+ config . loader . loadSettings ( ) . then ( ( ) => {
37
+ expect ( config . getSettings ( 'system' ) ) . toEqual ( {
38
+ applicationName : 'Mighty Mouse' ,
39
+ applicationUrl : 'http://localhost:8000' ,
40
+ } ) ;
39
41
40
- expect ( config . getSettings ( [ 'system' , 'applicationName' ] ) ) . toEqual ( 'Mighty Mouse' ) ;
41
- expect ( config . getSettings ( 'system.applicationName' ) ) . toEqual ( 'Mighty Mouse' ) ;
42
+ expect ( config . getSettings ( [ 'system' , 'applicationName' ] ) ) . toEqual ( 'Mighty Mouse' ) ;
43
+ expect ( config . getSettings ( 'system.applicationName' ) ) . toEqual ( 'Mighty Mouse' ) ;
42
44
43
- expect ( config . getSettings ( [ 'system' , 'applicationUrl' ] ) ) . toEqual ( 'http://localhost:8000' ) ;
44
- expect ( config . getSettings ( 'system.applicationUrl' ) ) . toEqual ( 'http://localhost:8000' ) ;
45
+ expect ( config . getSettings ( [ 'system' , 'applicationUrl' ] ) ) . toEqual ( 'http://localhost:8000' ) ;
46
+ expect ( config . getSettings ( 'system.applicationUrl' ) ) . toEqual ( 'http://localhost:8000' ) ;
45
47
46
- expect ( config . getSettings ( 'i18n' ) ) . toEqual ( {
47
- locale : 'en'
48
- } ) ;
48
+ expect ( config . getSettings ( 'i18n' ) ) . toEqual ( {
49
+ locale : 'en' ,
50
+ } ) ;
49
51
50
- expect ( config . getSettings ( [ 'i18n' , 'locale' ] ) ) . toEqual ( 'en' ) ;
51
- expect ( config . getSettings ( 'i18n.locale' ) ) . toEqual ( 'en' ) ;
52
- } ) ;
53
- } )
54
- ) ) ;
55
-
56
- it ( 'should be able to get setting(s) using `key` (zero value)' , async (
57
- inject ( [ ConfigService ] , ( config : ConfigService ) => {
58
- config . loader . loadSettings ( ) . then ( ( ) => {
59
- expect ( config . getSettings ( 'falsy.zero' ) ) . toEqual ( 0 ) ;
60
- } ) ;
61
- } )
62
- ) ) ;
63
-
64
- it ( 'should be able to get setting(s) using `key` (null value)' , async (
65
- inject ( [ ConfigService ] , ( config : ConfigService ) => {
66
- config . loader . loadSettings ( ) . then ( ( ) => {
67
- expect ( config . getSettings ( 'falsy.null' ) ) . toBeNull ( ) ;
68
- } ) ;
69
- } )
70
- ) ) ;
71
-
72
- it ( 'should be able to get setting(s) using `key` (empty string)' , async (
73
- inject ( [ ConfigService ] , ( config : ConfigService ) => {
74
- config . loader . loadSettings ( ) . then ( ( ) => {
75
- expect ( config . getSettings ( 'falsy.emptyString' ) ) . toEqual ( '' ) ;
76
- } ) ;
77
- } )
78
- ) ) ;
79
-
80
- it ( 'should be able to get `default value` w/invalid `key`' , async (
81
- inject ( [ ConfigService ] , ( config : ConfigService ) => {
82
- config . loader . loadSettings ( ) . then ( ( ) => {
83
- expect ( config . getSettings ( 'layout' , 'default' ) ) . toEqual ( 'default' ) ;
84
- } ) ;
85
- } )
86
- ) ) ;
87
-
88
- it ( 'should throw if you provide an invalid `key` w/o `default value`' , async (
89
- inject ( [ ConfigService ] , ( config : ConfigService ) => {
90
- config . loader . loadSettings ( ) . then ( ( ) => {
91
- expect ( ( ) => config . getSettings ( 'layout' ) ) . toThrowError ( 'No setting found with the specified key [layout]!' ) ;
92
- } ) ;
93
- } )
94
- ) ) ;
52
+ expect ( config . getSettings ( [ 'i18n' , 'locale' ] ) ) . toEqual ( 'en' ) ;
53
+ expect ( config . getSettings ( 'i18n.locale' ) ) . toEqual ( 'en' ) ;
54
+ } ) ;
55
+ } )
56
+ )
57
+ ) ;
58
+
59
+ it (
60
+ 'should be able to get setting(s) using `key` (zero value)' ,
61
+ waitForAsync (
62
+ inject ( [ ConfigService ] , ( config : ConfigService ) => {
63
+ config . loader . loadSettings ( ) . then ( ( ) => {
64
+ expect ( config . getSettings ( 'falsy.zero' ) ) . toEqual ( 0 ) ;
65
+ } ) ;
66
+ } )
67
+ )
68
+ ) ;
69
+
70
+ it (
71
+ 'should be able to get setting(s) using `key` (null value)' ,
72
+ waitForAsync (
73
+ inject ( [ ConfigService ] , ( config : ConfigService ) => {
74
+ config . loader . loadSettings ( ) . then ( ( ) => {
75
+ expect ( config . getSettings ( 'falsy.null' ) ) . toBeNull ( ) ;
76
+ } ) ;
77
+ } )
78
+ )
79
+ ) ;
80
+
81
+ it (
82
+ 'should be able to get setting(s) using `key` (empty string)' ,
83
+ waitForAsync (
84
+ inject ( [ ConfigService ] , ( config : ConfigService ) => {
85
+ config . loader . loadSettings ( ) . then ( ( ) => {
86
+ expect ( config . getSettings ( 'falsy.emptyString' ) ) . toEqual ( '' ) ;
87
+ } ) ;
88
+ } )
89
+ )
90
+ ) ;
91
+
92
+ it (
93
+ 'should be able to get `default value` w/invalid `key`' ,
94
+ waitForAsync (
95
+ inject ( [ ConfigService ] , ( config : ConfigService ) => {
96
+ config . loader . loadSettings ( ) . then ( ( ) => {
97
+ expect ( config . getSettings ( 'layout' , 'default' ) ) . toEqual ( 'default' ) ;
98
+ } ) ;
99
+ } )
100
+ )
101
+ ) ;
102
+
103
+ it (
104
+ 'should throw if you provide an invalid `key` w/o `default value`' ,
105
+ waitForAsync (
106
+ inject ( [ ConfigService ] , ( config : ConfigService ) => {
107
+ config . loader . loadSettings ( ) . then ( ( ) => {
108
+ expect ( ( ) => config . getSettings ( 'layout' ) ) . toThrowError ( 'No setting found with the specified key [layout]!' ) ;
109
+ } ) ;
110
+ } )
111
+ )
112
+ ) ;
95
113
} ) ;
96
114
} ) ;
0 commit comments