1*26ad19fcSEvan Baconimport { buildAsyncRequire } from '../buildAsyncRequire';
2*26ad19fcSEvan Baconimport { loadBundleAsync } from '../loadBundle';
3*26ad19fcSEvan Bacon
4*26ad19fcSEvan Baconexport const asMock = <T extends (...args: any[]) => any>(fn: T): jest.MockedFunction<T> =>
5*26ad19fcSEvan Bacon  fn as jest.MockedFunction<T>;
6*26ad19fcSEvan Bacon
7*26ad19fcSEvan Baconjest.mock('../loadBundle', () => ({
8*26ad19fcSEvan Bacon  loadBundleAsync: jest.fn(async () => {}),
9*26ad19fcSEvan Bacon}));
10*26ad19fcSEvan Bacon
11*26ad19fcSEvan Baconconst originalEnv = process.env.NODE_ENV;
12*26ad19fcSEvan BaconbeforeEach(() => {
13*26ad19fcSEvan Bacon  process.env.NODE_ENV = 'development';
14*26ad19fcSEvan Bacon});
15*26ad19fcSEvan Bacon
16*26ad19fcSEvan BaconafterAll(() => {
17*26ad19fcSEvan Bacon  process.env.NODE_ENV = originalEnv;
18*26ad19fcSEvan Bacon});
19*26ad19fcSEvan Bacon
20*26ad19fcSEvan Baconit(`builds required object`, async () => {
21*26ad19fcSEvan Bacon  const asyncRequire = buildAsyncRequire();
22*26ad19fcSEvan Bacon  expect(asyncRequire).toBeInstanceOf(Function);
23*26ad19fcSEvan Bacon});
24*26ad19fcSEvan Bacon
25*26ad19fcSEvan Baconit(`loads the module with \`loadBundleAsync\` if the module has not been loaded already`, async () => {
26*26ad19fcSEvan Bacon  const asyncRequire = buildAsyncRequire();
27*26ad19fcSEvan Bacon
28*26ad19fcSEvan Bacon  const myModule = asyncRequire('/bacon.bundle?platform=ios');
29*26ad19fcSEvan Bacon  expect(myModule).toEqual(expect.any(Promise));
30*26ad19fcSEvan Bacon
31*26ad19fcSEvan Bacon  // Did attempt to fetch the bundle
32*26ad19fcSEvan Bacon  expect(loadBundleAsync).toBeCalledWith('/bacon.bundle?platform=ios');
33*26ad19fcSEvan Bacon});
34