1import { getAccountUsername } from '@expo/config'; 2import { ExpoConfig } from 'expo/config'; 3import { AndroidConfig, IOSConfig } from 'expo/config-plugins'; 4 5import withUpdates from '../withUpdates'; 6 7jest.mock('@expo/config'); 8 9describe('Updates plugin', () => { 10 beforeAll(() => { 11 const config = getConfig(); 12 jest.spyOn(AndroidConfig.Updates, 'withUpdates').mockReturnValue(config); 13 jest.spyOn(IOSConfig.Updates, 'withUpdates').mockReturnValue(config); 14 }); 15 16 afterAll(() => { 17 jest.clearAllMocks(); 18 }); 19 20 it('passes in expo username, resolved by getAccountUsername', () => { 21 const expoUsername = 'some-username'; 22 // @ts-ignore: return the username so we can validate it is passed to the ios/android plugins 23 getAccountUsername.mockReturnValue(expoUsername); 24 25 withUpdates(getConfig()); 26 27 // @ts-ignore: this is an expect extension and is not defined on the type 28 const _ = expect.literallyAnything(); 29 expect(AndroidConfig.Updates.withUpdates).toHaveBeenCalledWith(_, { expoUsername }); 30 expect(IOSConfig.Updates.withUpdates).toHaveBeenCalledWith(_, { expoUsername }); 31 }); 32 33 it('passes the config object to getAccountUsername', () => { 34 withUpdates(getConfig({ owner: 'real-owner' })); 35 expect(getAccountUsername).toHaveBeenCalledWith( 36 expect.objectContaining({ owner: 'real-owner' }) 37 ); 38 }); 39}); 40 41function getConfig(options = {}): ExpoConfig { 42 return { 43 name: 'foo', 44 slug: 'my-app', 45 ...options, 46 }; 47} 48 49// expect.anything() doesn't match for undefined | null 50expect.extend({ 51 literallyAnything: () => { 52 return { 53 message: () => 'This value is ignored', 54 pass: true, 55 }; 56 }, 57}); 58