@@ -72,9 +72,12 @@ describe('Mock methods', () => {
7272} ) ;
7373
7474describe ( 'Mock property' , ( ) => {
75+ const fooSymbol = Symbol ( 'foo' ) ;
7576 const config = {
7677 enableCache : true ,
7778 delay : 10 ,
79+ [ fooSymbol ] : 'bar' ,
80+ 1 : 'one' ,
7881 } ;
7982
8083 const plainObj = Object . create ( null ) ;
@@ -89,6 +92,24 @@ describe('Mock property', () => {
8992 assert . equal ( plainObj . testKey , 'mockValue' , 'testKey is mockValue' ) ;
9093 } ) ;
9194
95+ it ( 'Should mock Symbol property successfully' , ( ) => {
96+ muk ( config , fooSymbol , 'mockValue' ) ;
97+ assert . equal ( config [ fooSymbol ] , 'mockValue' , 'fooSymbol is mockValue' ) ;
98+ assert . equal ( isMocked ( config , fooSymbol ) , true , 'fooSymbol is mocked' ) ;
99+ restore ( ) ;
100+ assert . equal ( config [ fooSymbol ] , 'bar' , 'fooSymbol is bar' ) ;
101+ assert . equal ( isMocked ( config , fooSymbol ) , false , 'fooSymbol is not mocked' ) ;
102+ } ) ;
103+
104+ it ( 'Should mock number property successfully' , ( ) => {
105+ muk ( config , 1 , 'mockValue' ) ;
106+ assert . equal ( config [ 1 ] , 'mockValue' , '1 is mockValue' ) ;
107+ assert . equal ( isMocked ( config , 1 ) , true , '1 is mocked' ) ;
108+ restore ( ) ;
109+ assert . equal ( config [ 1 ] , 'one' , '1 is one' ) ;
110+ assert . equal ( isMocked ( config , 1 ) , false , '1 is not mocked' ) ;
111+ } ) ;
112+
92113 it ( 'Should alias mock method work' , ( ) => {
93114 mock ( plainObj , 'testKey' , 'mockValue' ) ;
94115 assert . equal ( plainObj . testKey , 'mockValue' , 'testKey is mockValue' ) ;
@@ -116,10 +137,10 @@ describe('Mock property', () => {
116137 muk ( process . env , 'HOME' , '/mockhome' ) ;
117138 muk ( config , 'notExistProp' , 'value' ) ;
118139 muk ( process . env , 'notExistProp' , 0 ) ;
119- assert . deepEqual ( Object . keys ( config ) , [ 'enableCache' , 'delay' , 'notExistProp' ] ) ;
140+ assert . deepEqual ( Object . keys ( config ) , [ '1' , ' enableCache', 'delay' , 'notExistProp' ] ) ;
120141
121142 restore ( ) ;
122- assert . deepEqual ( Object . keys ( config ) , [ 'enableCache' , 'delay' ] ) ;
143+ assert . deepEqual ( Object . keys ( config ) , [ '1' , ' enableCache', 'delay' ] ) ;
123144 assert . equal ( config . enableCache , true , 'enableCache is true' ) ;
124145 assert . equal ( config . delay , 10 , 'delay is 10' ) ;
125146 assert . equal ( process . env . HOME , home , 'process.env.HOME is ' + home ) ;
0 commit comments