|
1 |
| -import { describe, expect, it } from '@jest/globals'; |
2 |
| - |
| 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'; |
3 | 8 | import {
|
4 | 9 | firebase,
|
5 | 10 | getCrashlytics,
|
@@ -79,4 +84,132 @@ describe('Crashlytics', function () {
|
79 | 84 | expect(setCrashlyticsCollectionEnabled).toBeDefined();
|
80 | 85 | });
|
81 | 86 | });
|
| 87 | + |
| 88 | + describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () { |
| 89 | + let checkV9Deprecation: CheckV9DeprecationFunction; |
| 90 | + |
| 91 | + beforeEach(function () { |
| 92 | + checkV9Deprecation = createCheckV9Deprecation('crashlytics'); |
| 93 | + |
| 94 | + // @ts-ignore test |
| 95 | + jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => { |
| 96 | + return new Proxy( |
| 97 | + {}, |
| 98 | + { |
| 99 | + get: () => jest.fn(), |
| 100 | + }, |
| 101 | + ); |
| 102 | + }); |
| 103 | + }); |
| 104 | + |
| 105 | + it('checkForUnsentReports', function () { |
| 106 | + const crashlytics = getCrashlytics(); |
| 107 | + checkV9Deprecation( |
| 108 | + () => checkForUnsentReports(crashlytics), |
| 109 | + () => crashlytics.checkForUnsentReports(), |
| 110 | + 'checkForUnsentReports', |
| 111 | + ); |
| 112 | + }); |
| 113 | + |
| 114 | + it('crash', function () { |
| 115 | + const crashlytics = getCrashlytics(); |
| 116 | + checkV9Deprecation( |
| 117 | + () => crash(crashlytics), |
| 118 | + () => crashlytics.crash(), |
| 119 | + 'crash', |
| 120 | + ); |
| 121 | + }); |
| 122 | + |
| 123 | + it('deleteUnsentReports', function () { |
| 124 | + const crashlytics = getCrashlytics(); |
| 125 | + checkV9Deprecation( |
| 126 | + () => deleteUnsentReports(crashlytics), |
| 127 | + () => crashlytics.deleteUnsentReports(), |
| 128 | + 'deleteUnsentReports', |
| 129 | + ); |
| 130 | + }); |
| 131 | + |
| 132 | + it('didCrashOnPreviousExecution', function () { |
| 133 | + const crashlytics = getCrashlytics(); |
| 134 | + checkV9Deprecation( |
| 135 | + () => didCrashOnPreviousExecution(crashlytics), |
| 136 | + () => crashlytics.didCrashOnPreviousExecution(), |
| 137 | + 'didCrashOnPreviousExecution', |
| 138 | + ); |
| 139 | + }); |
| 140 | + |
| 141 | + it('log', function () { |
| 142 | + const crashlytics = getCrashlytics(); |
| 143 | + checkV9Deprecation( |
| 144 | + () => log(crashlytics, 'message'), |
| 145 | + () => crashlytics.log('message'), |
| 146 | + 'log', |
| 147 | + ); |
| 148 | + }); |
| 149 | + |
| 150 | + it('setAttribute', function () { |
| 151 | + const crashlytics = getCrashlytics(); |
| 152 | + checkV9Deprecation( |
| 153 | + () => setAttribute(crashlytics, 'name', 'value'), |
| 154 | + () => crashlytics.setAttribute('name', 'value'), |
| 155 | + 'setAttribute', |
| 156 | + ); |
| 157 | + }); |
| 158 | + |
| 159 | + it('setAttributes', function () { |
| 160 | + const crashlytics = getCrashlytics(); |
| 161 | + checkV9Deprecation( |
| 162 | + () => setAttributes(crashlytics, {}), |
| 163 | + () => crashlytics.setAttributes({}), |
| 164 | + 'setAttributes', |
| 165 | + ); |
| 166 | + }); |
| 167 | + |
| 168 | + it('setUserId', function () { |
| 169 | + const crashlytics = getCrashlytics(); |
| 170 | + checkV9Deprecation( |
| 171 | + () => setUserId(crashlytics, 'id'), |
| 172 | + () => crashlytics.setUserId('id'), |
| 173 | + 'setUserId', |
| 174 | + ); |
| 175 | + }); |
| 176 | + |
| 177 | + it('recordError', function () { |
| 178 | + const crashlytics = getCrashlytics(); |
| 179 | + checkV9Deprecation( |
| 180 | + () => recordError(crashlytics, new Error(), 'name'), |
| 181 | + () => crashlytics.recordError(new Error(), 'name'), |
| 182 | + 'recordError', |
| 183 | + ); |
| 184 | + }); |
| 185 | + |
| 186 | + it('sendUnsentReports', function () { |
| 187 | + const crashlytics = getCrashlytics(); |
| 188 | + checkV9Deprecation( |
| 189 | + () => sendUnsentReports(crashlytics), |
| 190 | + () => crashlytics.sendUnsentReports(), |
| 191 | + 'sendUnsentReports', |
| 192 | + ); |
| 193 | + }); |
| 194 | + |
| 195 | + it('setCrashlyticsCollectionEnabled', function () { |
| 196 | + const crashlytics = getCrashlytics(); |
| 197 | + checkV9Deprecation( |
| 198 | + () => setCrashlyticsCollectionEnabled(crashlytics, true), |
| 199 | + () => crashlytics.setCrashlyticsCollectionEnabled(true), |
| 200 | + 'setCrashlyticsCollectionEnabled', |
| 201 | + ); |
| 202 | + }); |
| 203 | + |
| 204 | + it('isCrashlyticsCollectionEnabled', function () { |
| 205 | + const crashlytics = getCrashlytics(); |
| 206 | + checkV9Deprecation( |
| 207 | + // swapped order here because we're deprecating the modular method and keeping the property on Crashlytics instance |
| 208 | + () => crashlytics.isCrashlyticsCollectionEnabled, |
| 209 | + () => isCrashlyticsCollectionEnabled(crashlytics), |
| 210 | + '', |
| 211 | + '`isCrashlyticsCollectionEnabled()` is deprecated, please use `Crashlytics.isCrashlyticsCollectionEnabled` property instead', |
| 212 | + ); |
| 213 | + }); |
| 214 | + }); |
82 | 215 | });
|
0 commit comments