1- import { async , inject } from '@angular/core/testing' ;
1+ import { inject , waitForAsync } from '@angular/core/testing' ;
22
33import { ConfigLoader , ConfigService , ConfigStaticLoader } from '../src' ;
44
@@ -10,7 +10,7 @@ describe('@ngx-config/core:', () => {
1010
1111 testModuleConfig ( {
1212 provide : ConfigLoader ,
13- useFactory : configFactory
13+ useFactory : configFactory ,
1414 } ) ;
1515 } ) ;
1616
@@ -29,68 +29,86 @@ describe('@ngx-config/core:', () => {
2929 } ) ;
3030 } ) ) ;
3131
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+ } ) ;
3941
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' ) ;
4244
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' ) ;
4547
46- expect ( config . getSettings ( 'i18n' ) ) . toEqual ( {
47- locale : 'en'
48- } ) ;
48+ expect ( config . getSettings ( 'i18n' ) ) . toEqual ( {
49+ locale : 'en' ,
50+ } ) ;
4951
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+ ) ;
95113 } ) ;
96114} ) ;
0 commit comments