1- import { describe , expect , it , jest } from '@jest/globals' ;
2- import { checkV9Deprecation } from '../../app/lib/common/unitTestUtils' ;
1+ import { describe , expect , it , jest , beforeEach } from '@jest/globals' ;
2+ // @ts -ignore test
3+ import FirebaseModule from '../../app/lib/internal/FirebaseModule' ;
4+ import {
5+ createCheckV9Deprecation ,
6+ CheckV9DeprecationFunction ,
7+ } from '../../app/lib/common/unitTestUtils' ;
38import {
49 firebase ,
510 getCrashlytics ,
@@ -81,146 +86,118 @@ describe('Crashlytics', function () {
8186 } ) ;
8287
8388 describe ( 'test `console.warn` is called for RNFB v8 API & not called for v9 API' , function ( ) {
84- it ( 'checkForUnsentReports' , function ( ) {
85- const crashlytics = getCrashlytics ( ) ;
86- // @ts -ignore test
87- const nativeMock = { checkForUnsentReports : jest . fn ( ) } ;
89+ let checkV9Deprecation : CheckV9DeprecationFunction ;
90+
91+ beforeEach ( function ( ) {
92+ checkV9Deprecation = createCheckV9Deprecation ( 'crashlytics' ) ;
93+
8894 // @ts -ignore test
89- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
95+ jest . spyOn ( FirebaseModule . prototype , 'native' , 'get' ) . mockImplementation ( ( ) => {
96+ return new Proxy (
97+ { } ,
98+ {
99+ get : ( ) => jest . fn ( ) ,
100+ } ,
101+ ) ;
102+ } ) ;
103+ } ) ;
90104
105+ it ( 'checkForUnsentReports' , function ( ) {
106+ const crashlytics = getCrashlytics ( ) ;
91107 checkV9Deprecation (
92108 ( ) => checkForUnsentReports ( crashlytics ) ,
93109 ( ) => crashlytics . checkForUnsentReports ( ) ,
110+ 'checkForUnsentReports' ,
94111 ) ;
95112 } ) ;
96113
97114 it ( 'crash' , function ( ) {
98115 const crashlytics = getCrashlytics ( ) ;
99- // @ts -ignore test
100- const nativeMock = { crash : jest . fn ( ) } ;
101- // @ts -ignore test
102- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
103-
104116 checkV9Deprecation (
105117 ( ) => crash ( crashlytics ) ,
106118 ( ) => crashlytics . crash ( ) ,
119+ 'crash' ,
107120 ) ;
108121 } ) ;
109122
110123 it ( 'deleteUnsentReports' , function ( ) {
111124 const crashlytics = getCrashlytics ( ) ;
112- // @ts -ignore test
113- const nativeMock = { deleteUnsentReports : jest . fn ( ) } ;
114- // @ts -ignore test
115- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
116-
117125 checkV9Deprecation (
118126 ( ) => deleteUnsentReports ( crashlytics ) ,
119127 ( ) => crashlytics . deleteUnsentReports ( ) ,
128+ 'deleteUnsentReports' ,
120129 ) ;
121130 } ) ;
122131
123132 it ( 'didCrashOnPreviousExecution' , function ( ) {
124133 const crashlytics = getCrashlytics ( ) ;
125- // @ts -ignore test
126- const nativeMock = { didCrashOnPreviousExecution : jest . fn ( ) } ;
127- // @ts -ignore test
128- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
129-
130134 checkV9Deprecation (
131135 ( ) => didCrashOnPreviousExecution ( crashlytics ) ,
132136 ( ) => crashlytics . didCrashOnPreviousExecution ( ) ,
137+ 'didCrashOnPreviousExecution' ,
133138 ) ;
134139 } ) ;
135140
136141 it ( 'log' , function ( ) {
137142 const crashlytics = getCrashlytics ( ) ;
138- // @ts -ignore test
139- const nativeMock = { log : jest . fn ( ) } ;
140- // @ts -ignore test
141- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
142-
143143 checkV9Deprecation (
144144 ( ) => log ( crashlytics , 'message' ) ,
145145 ( ) => crashlytics . log ( 'message' ) ,
146+ 'log' ,
146147 ) ;
147148 } ) ;
148149
149150 it ( 'setAttribute' , function ( ) {
150151 const crashlytics = getCrashlytics ( ) ;
151- // @ts -ignore test
152- const nativeMock = { setAttribute : jest . fn ( ) } ;
153- // @ts -ignore test
154- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
155-
156152 checkV9Deprecation (
157153 ( ) => setAttribute ( crashlytics , 'name' , 'value' ) ,
158154 ( ) => crashlytics . setAttribute ( 'name' , 'value' ) ,
155+ 'setAttribute' ,
159156 ) ;
160157 } ) ;
161158
162159 it ( 'setAttributes' , function ( ) {
163160 const crashlytics = getCrashlytics ( ) ;
164- // @ts -ignore test
165- const nativeMock = { setAttributes : jest . fn ( ) } ;
166- // @ts -ignore test
167- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
168-
169161 checkV9Deprecation (
170162 ( ) => setAttributes ( crashlytics , { } ) ,
171163 ( ) => crashlytics . setAttributes ( { } ) ,
164+ 'setAttributes' ,
172165 ) ;
173166 } ) ;
174167
175168 it ( 'setUserId' , function ( ) {
176169 const crashlytics = getCrashlytics ( ) ;
177- // @ts -ignore test
178- const nativeMock = { setUserId : jest . fn ( ) } ;
179- // @ts -ignore test
180- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
181-
182170 checkV9Deprecation (
183171 ( ) => setUserId ( crashlytics , 'id' ) ,
184172 ( ) => crashlytics . setUserId ( 'id' ) ,
173+ 'setUserId' ,
185174 ) ;
186175 } ) ;
187176
188177 it ( 'recordError' , function ( ) {
189178 const crashlytics = getCrashlytics ( ) ;
190- // @ts -ignore test
191- const nativeMock = { recordError : jest . fn ( ) } ;
192- // @ts -ignore test
193- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
194-
195179 checkV9Deprecation (
196180 ( ) => recordError ( crashlytics , new Error ( ) , 'name' ) ,
197181 ( ) => crashlytics . recordError ( new Error ( ) , 'name' ) ,
182+ 'recordError' ,
198183 ) ;
199184 } ) ;
200185
201186 it ( 'sendUnsentReports' , function ( ) {
202187 const crashlytics = getCrashlytics ( ) ;
203- // @ts -ignore test
204- const nativeMock = { sendUnsentReports : jest . fn ( ) } ;
205- // @ts -ignore test
206- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
207-
208188 checkV9Deprecation (
209189 ( ) => sendUnsentReports ( crashlytics ) ,
210190 ( ) => crashlytics . sendUnsentReports ( ) ,
191+ 'sendUnsentReports' ,
211192 ) ;
212193 } ) ;
213194
214195 it ( 'setCrashlyticsCollectionEnabled' , function ( ) {
215196 const crashlytics = getCrashlytics ( ) ;
216- // @ts -ignore test
217- const nativeMock = { setCrashlyticsCollectionEnabled : jest . fn ( ) } ;
218- // @ts -ignore test
219- jest . spyOn ( crashlytics , 'native' , 'get' ) . mockReturnValue ( nativeMock ) ;
220-
221197 checkV9Deprecation (
222198 ( ) => setCrashlyticsCollectionEnabled ( crashlytics , true ) ,
223199 ( ) => crashlytics . setCrashlyticsCollectionEnabled ( true ) ,
200+ 'setCrashlyticsCollectionEnabled' ,
224201 ) ;
225202 } ) ;
226203
@@ -230,6 +207,8 @@ describe('Crashlytics', function () {
230207 // swapped order here because we're deprecating the modular method and keeping the property on Crashlytics instance
231208 ( ) => crashlytics . isCrashlyticsCollectionEnabled ,
232209 ( ) => isCrashlyticsCollectionEnabled ( crashlytics ) ,
210+ '' ,
211+ '`isCrashlyticsCollectionEnabled()` is deprecated, please use `Crashlytics.isCrashlyticsCollectionEnabled` property instead' ,
233212 ) ;
234213 } ) ;
235214 } ) ;
0 commit comments