@@ -2794,7 +2794,13 @@ describe('<Data> Parser', function() {
27942794 expect ( result2 [ 1 ] ) . to . be . instanceof ( FooClass )
27952795 } )
27962796
2797- it ( 'data store object with inner instances from global' , async ( ) => {
2797+ it ( 'uses classes from global by default for data store object with inner instances' , async ( ) => {
2798+ // eslint-disable-next-line no-console
2799+ const _nativeConsoleWarn = console . warn
2800+
2801+ // eslint-disable-next-line no-console
2802+ const spyConsoleWarn = console . warn = chai . spy ( )
2803+
27982804 global . FooClass = class FooClass {
27992805 }
28002806
@@ -2831,6 +2837,77 @@ describe('<Data> Parser', function() {
28312837
28322838 expect ( result2 [ 1 ] . foo ) . to . be . instanceof ( FooClass )
28332839 expect ( result2 [ 1 ] . bar ) . to . be . instanceof ( BarFun )
2840+
2841+ expect ( spyConsoleWarn ) . to . have . been . called . exactly ( 6 )
2842+
2843+ const warningMsg = (
2844+ 'Resolving DataTable classes from the global scope is deprecated ' +
2845+ 'and it won\'t be supported in the nearest future. ' +
2846+ 'Instead, you should register your DataTable classes ' +
2847+ 'using the following method Backendless.Data.mapTableToClass'
2848+ )
2849+
2850+ expect ( spyConsoleWarn ) . on . nth ( 1 ) . be . called . with ( warningMsg )
2851+ expect ( spyConsoleWarn ) . on . nth ( 2 ) . be . called . with ( warningMsg )
2852+ expect ( spyConsoleWarn ) . on . nth ( 3 ) . be . called . with ( warningMsg )
2853+ expect ( spyConsoleWarn ) . on . nth ( 4 ) . be . called . with ( warningMsg )
2854+ expect ( spyConsoleWarn ) . on . nth ( 5 ) . be . called . with ( warningMsg )
2855+ expect ( spyConsoleWarn ) . on . nth ( 6 ) . be . called . with ( warningMsg )
2856+
2857+ // eslint-disable-next-line no-console
2858+ console . warn = _nativeConsoleWarn
2859+ } )
2860+
2861+ it ( 'does not use classes from global for data store object with inner instances' , async ( ) => {
2862+ // eslint-disable-next-line no-console
2863+ const _nativeConsoleWarn = console . warn
2864+
2865+ // eslint-disable-next-line no-console
2866+ const spyConsoleWarn = console . warn = chai . spy ( )
2867+
2868+ Backendless . useTableClassesFromGlobalScope = false
2869+
2870+ global . FooClass = class FooClass {
2871+ }
2872+
2873+ global . BarFun = function BarFun ( ) {
2874+ }
2875+
2876+ dataStore = Backendless . Data . of ( tableName )
2877+
2878+ const result1 = dataStore . parseResponse ( {
2879+ foo : { ___class : 'FooClass' , value : 1 , } ,
2880+ bar : { ___class : 'BarFun' , value : 2 , }
2881+ } )
2882+
2883+ const result2 = dataStore . parseResponse ( [
2884+ { foo : { ___class : 'FooClass' , value : 3 , } , bar : { ___class : 'BarFun' , value : 5 , } } ,
2885+ { foo : { ___class : 'FooClass' , value : 4 , } , bar : { ___class : 'BarFun' , value : 6 , } }
2886+ ] )
2887+
2888+ expect ( result1 ) . to . be . eql ( {
2889+ foo : { ___class : 'FooClass' , value : 1 , } ,
2890+ bar : { ___class : 'BarFun' , value : 2 , }
2891+ } )
2892+
2893+ expect ( result1 . foo ) . to . not . be . instanceof ( FooClass )
2894+ expect ( result1 . bar ) . to . not . be . instanceof ( BarFun )
2895+
2896+ expect ( result2 ) . to . be . eql ( [
2897+ { foo : { ___class : 'FooClass' , value : 3 , } , bar : { ___class : 'BarFun' , value : 5 , } } ,
2898+ { foo : { ___class : 'FooClass' , value : 4 , } , bar : { ___class : 'BarFun' , value : 6 , } }
2899+ ] )
2900+
2901+ expect ( result2 [ 0 ] . foo ) . to . not . be . instanceof ( FooClass )
2902+ expect ( result2 [ 0 ] . bar ) . to . not . be . instanceof ( BarFun )
2903+
2904+ expect ( result2 [ 1 ] . foo ) . to . not . be . instanceof ( FooClass )
2905+ expect ( result2 [ 1 ] . bar ) . to . not . be . instanceof ( BarFun )
2906+
2907+ expect ( spyConsoleWarn ) . to . have . been . called . exactly ( 0 )
2908+
2909+ // eslint-disable-next-line no-console
2910+ console . warn = _nativeConsoleWarn
28342911 } )
28352912
28362913 it ( 'data store object with inner instances from classesMap' , async ( ) => {
0 commit comments