|
3 | 3 | getUserCallSite, |
4 | 4 | resetWarningsForTest, |
5 | 5 | warnIfAndroidSkew, |
| 6 | + warnIfIosVerticalAlign, |
6 | 7 | warnIfSentinelLeak, |
7 | 8 | } from '../dev'; |
8 | 9 |
|
@@ -167,6 +168,67 @@ describe('warnIfAndroidSkew', () => { |
167 | 168 | }); |
168 | 169 | }); |
169 | 170 |
|
| 171 | +describe('warnIfIosVerticalAlign', () => { |
| 172 | + const realOS = Platform.OS; |
| 173 | + let warnSpy: jest.SpyInstance; |
| 174 | + |
| 175 | + beforeEach(() => { |
| 176 | + resetWarningsForTest(); |
| 177 | + warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => undefined); |
| 178 | + }); |
| 179 | + |
| 180 | + afterEach(() => { |
| 181 | + warnSpy.mockRestore(); |
| 182 | + Object.defineProperty(Platform, 'OS', { value: realOS, configurable: true }); |
| 183 | + }); |
| 184 | + |
| 185 | + function setPlatform(os: 'ios' | 'android' | 'web'): void { |
| 186 | + Object.defineProperty(Platform, 'OS', { value: os, configurable: true }); |
| 187 | + } |
| 188 | + |
| 189 | + it('warns when middle is set on iOS', () => { |
| 190 | + setPlatform('ios'); |
| 191 | + warnIfIosVerticalAlign('middle'); |
| 192 | + expect(warnSpy).toHaveBeenCalledTimes(1); |
| 193 | + expect(warnSpy.mock.calls[0][0]).toMatch(/`vertical-align: middle` has no effect on iOS/); |
| 194 | + expect(warnSpy.mock.calls[0][0]).toMatch(/wrap the Text in a View with `justify-content/); |
| 195 | + }); |
| 196 | + |
| 197 | + it('warns for top and bottom too', () => { |
| 198 | + setPlatform('ios'); |
| 199 | + warnIfIosVerticalAlign('top'); |
| 200 | + warnIfIosVerticalAlign('bottom'); |
| 201 | + expect(warnSpy).toHaveBeenCalledTimes(2); |
| 202 | + }); |
| 203 | + |
| 204 | + it('does NOT warn for the default `auto` value', () => { |
| 205 | + setPlatform('ios'); |
| 206 | + warnIfIosVerticalAlign('auto'); |
| 207 | + expect(warnSpy).not.toHaveBeenCalled(); |
| 208 | + }); |
| 209 | + |
| 210 | + it('does NOT warn on Android', () => { |
| 211 | + setPlatform('android'); |
| 212 | + warnIfIosVerticalAlign('middle'); |
| 213 | + expect(warnSpy).not.toHaveBeenCalled(); |
| 214 | + }); |
| 215 | + |
| 216 | + it('does NOT warn on web', () => { |
| 217 | + setPlatform('web'); |
| 218 | + warnIfIosVerticalAlign('middle'); |
| 219 | + expect(warnSpy).not.toHaveBeenCalled(); |
| 220 | + }); |
| 221 | + |
| 222 | + it('dedupes per value so each distinct value warns once', () => { |
| 223 | + setPlatform('ios'); |
| 224 | + warnIfIosVerticalAlign('middle'); |
| 225 | + warnIfIosVerticalAlign('middle'); |
| 226 | + warnIfIosVerticalAlign('bottom'); |
| 227 | + warnIfIosVerticalAlign('bottom'); |
| 228 | + expect(warnSpy).toHaveBeenCalledTimes(2); |
| 229 | + }); |
| 230 | +}); |
| 231 | + |
170 | 232 | describe('warning call-site picker', () => { |
171 | 233 | it('picks the first user-code frame from a typical stack', () => { |
172 | 234 | const stack = [ |
|
0 commit comments