@@ -29,22 +29,66 @@ describe('mapFacetsCached', () => {
29
29
expect ( mapFunction ) . toHaveBeenCalledTimes ( 1 )
30
30
} )
31
31
32
- it ( 'gets NO_VALUE as a value from a single source before any subscription ' , ( ) => {
32
+ it ( 'gets NO_VALUE as a value from a single source if it also has NO_VALUE ' , ( ) => {
33
33
const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
34
- const sourceFacet = createFacet ( { initialValue : 'initial value' } )
34
+ const sourceFacet = createFacet ( { initialValue : NO_VALUE } )
35
35
const mapFacet = mapFacetsCached ( [ sourceFacet ] , mapFunction , ( ) => ( ) => false )
36
36
37
37
expect ( mapFacet . get ( ) ) . toBe ( NO_VALUE )
38
38
} )
39
39
40
- it ( 'gets NO_VALUE as a value from multiple sources before any subscription ' , ( ) => {
40
+ it ( 'gets NO_VALUE as a value from multiple sources if they also have NO_VALUE ' , ( ) => {
41
41
const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
42
42
const sourceAFacet = createFacet ( { initialValue : 'initial value' } )
43
- const sourceBFacet = createFacet ( { initialValue : 'initial value' } )
43
+ const sourceBFacet = createFacet ( { initialValue : NO_VALUE } )
44
44
const mapFacet = mapFacetsCached ( [ sourceAFacet , sourceBFacet ] , mapFunction , ( ) => ( ) => false )
45
45
46
46
expect ( mapFacet . get ( ) ) . toBe ( NO_VALUE )
47
47
} )
48
+
49
+ it ( 'can get the mapped value from a single source before any subscription' , ( ) => {
50
+ const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
51
+ const sourceFacet = createFacet ( { initialValue : 'initial value' } )
52
+ const mapFacet = mapFacetsCached ( [ sourceFacet ] , mapFunction , ( ) => ( ) => false )
53
+
54
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
55
+ } )
56
+
57
+ it ( 'can get the mapped value from multiple sources before any subscription' , ( ) => {
58
+ const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
59
+ const sourceAFacet = createFacet ( { initialValue : 'initial value' } )
60
+ const sourceBFacet = createFacet ( { initialValue : 'initial value' } )
61
+ const mapFacet = mapFacetsCached ( [ sourceAFacet , sourceBFacet ] , mapFunction , ( ) => ( ) => false )
62
+
63
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
64
+ } )
65
+
66
+ it ( 'caches calls to the mapFunction through a get call before any subscription, given a single source' , ( ) => {
67
+ const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
68
+ const sourceFacet = createFacet ( { initialValue : 'initial value' } )
69
+ const mapFacet = mapFacetsCached ( [ sourceFacet ] , mapFunction , ( ) => ( ) => false )
70
+
71
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
72
+ expect ( mapFunction ) . toHaveBeenCalledTimes ( 1 )
73
+
74
+ mapFunction . mockClear ( )
75
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
76
+ expect ( mapFunction ) . not . toHaveBeenCalled ( )
77
+ } )
78
+
79
+ it ( 'caches calls to the mapFunction through a get call before any subscription, given multiple sources' , ( ) => {
80
+ const mapFunction = jest . fn ( ) . mockReturnValue ( 'dummy' )
81
+ const sourceAFacet = createFacet ( { initialValue : 'initial value' } )
82
+ const sourceBFacet = createFacet ( { initialValue : 'initial value' } )
83
+ const mapFacet = mapFacetsCached ( [ sourceAFacet , sourceBFacet ] , mapFunction , ( ) => ( ) => false )
84
+
85
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
86
+ expect ( mapFunction ) . toHaveBeenCalledTimes ( 1 )
87
+
88
+ mapFunction . mockClear ( )
89
+ expect ( mapFacet . get ( ) ) . toBe ( 'dummy' )
90
+ expect ( mapFunction ) . not . toHaveBeenCalled ( )
91
+ } )
48
92
} )
49
93
50
94
describe ( 'mapFacetsLightweight' , ( ) => {
0 commit comments