diff --git a/bunfig.toml b/bunfig.toml new file mode 100644 index 00000000..37ff1f94 --- /dev/null +++ b/bunfig.toml @@ -0,0 +1,2 @@ +[test] +preload = ["./src/__tests__/setup.ts"] diff --git a/src/__tests__/setup.ts b/src/__tests__/setup.ts new file mode 100644 index 00000000..2c9459e7 --- /dev/null +++ b/src/__tests__/setup.ts @@ -0,0 +1,17 @@ +import { mock } from 'bun:test'; + +mock.module('react-native', () => { + return { + Platform: { + OS: 'ios', + }, + }; +}); + +mock.module('../i18n', () => { + return { + default: { + t: (key: string) => key, + }, + }; +}); diff --git a/src/__tests__/utils.test.ts b/src/__tests__/utils.test.ts new file mode 100644 index 00000000..1b648c25 --- /dev/null +++ b/src/__tests__/utils.test.ts @@ -0,0 +1,36 @@ +import { describe, expect, test, mock } from 'bun:test'; + +mock.module('react-native', () => { + return { + Platform: { + OS: 'ios', + }, + }; +}); + +mock.module('../i18n', () => { + return { + default: { + t: (key: string) => key, + }, + }; +}); + +import { joinUrls } from '../utils'; + +describe('joinUrls', () => { + test('returns undefined when fileName is not provided', () => { + expect(joinUrls(['example.com'])).toBeUndefined(); + }); + + test('returns an empty array when paths is empty', () => { + expect(joinUrls([], 'file.txt')).toEqual([]); + }); + + test('maps over paths and prepends https:// with fileName', () => { + expect(joinUrls(['example.com', 'test.org'], 'file.txt')).toEqual([ + 'https://example.com/file.txt', + 'https://test.org/file.txt', + ]); + }); +});