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