Skip to content

Commit 6e663b9

Browse files
🧪 Add tests for joinUrls logic in utils.ts (#521)
Adds unit tests and test suite configuration for testing src/utils.ts, achieving 100% test coverage for the joinUrls logic. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
1 parent 7acce0d commit 6e663b9

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎bunfig.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[test]
2+
preload = ["./src/__tests__/setup.ts"]

‎src/__tests__/setup.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { mock } from 'bun:test';
2+
3+
mock.module('react-native', () => {
4+
return {
5+
Platform: {
6+
OS: 'ios',
7+
},
8+
};
9+
});
10+
11+
mock.module('../i18n', () => {
12+
return {
13+
default: {
14+
t: (key: string) => key,
15+
},
16+
};
17+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { describe, expect, test, mock } from 'bun:test';
2+
3+
mock.module('react-native', () => {
4+
return {
5+
Platform: {
6+
OS: 'ios',
7+
},
8+
};
9+
});
10+
11+
mock.module('../i18n', () => {
12+
return {
13+
default: {
14+
t: (key: string) => key,
15+
},
16+
};
17+
});
18+
19+
import { joinUrls } from '../utils';
20+
21+
describe('joinUrls', () => {
22+
test('returns undefined when fileName is not provided', () => {
23+
expect(joinUrls(['example.com'])).toBeUndefined();
24+
});
25+
26+
test('returns an empty array when paths is empty', () => {
27+
expect(joinUrls([], 'file.txt')).toEqual([]);
28+
});
29+
30+
test('maps over paths and prepends https:// with fileName', () => {
31+
expect(joinUrls(['example.com', 'test.org'], 'file.txt')).toEqual([
32+
'https://example.com/file.txt',
33+
'https://test.org/file.txt',
34+
]);
35+
});
36+
});

0 commit comments

Comments
 (0)