Skip to content

Commit f76e596

Browse files
Update URL-test.js
1 parent 7fd96f8 commit f76e596

File tree

1 file changed

+32
-59
lines changed
  • packages/react-native/Libraries/Blob/__tests__

1 file changed

+32
-59
lines changed

packages/react-native/Libraries/Blob/__tests__/URL-test.js

Lines changed: 32 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,38 @@
1313
const URL = require('../URL').URL;
1414

1515
describe('URL', function () {
16-
it('should correctly parse all URL components', () => {
16+
it('should pass Mozilla Dev Network examples', () => {
17+
const a = new URL('/', 'https://developer.mozilla.org');
18+
expect(a.href).toBe('https://developer.mozilla.org/');
19+
const b = new URL('https://developer.mozilla.org');
20+
expect(b.href).toBe('https://developer.mozilla.org/');
21+
const c = new URL('en-US/docs', b);
22+
expect(c.href).toBe('https://developer.mozilla.org/en-US/docs');
23+
const d = new URL('/en-US/docs', b);
24+
expect(d.href).toBe('https://developer.mozilla.org/en-US/docs');
25+
const f = new URL('/en-US/docs', d);
26+
expect(f.href).toBe('https://developer.mozilla.org/en-US/docs');
27+
// from original test suite, but requires complex implementation
28+
// const g = new URL(
29+
// '/en-US/docs',
30+
// 'https://developer.mozilla.org/fr-FR/toto',
31+
// );
32+
// expect(g.href).toBe('https://developer.mozilla.org/en-US/docs');
33+
const h = new URL('/en-US/docs', a);
34+
expect(h.href).toBe('https://developer.mozilla.org/en-US/docs');
35+
const i = new URL('http://github.com', 'http://google.com');
36+
expect(i.href).toBe('http://github.com/');
37+
// Support Bare Hosts
38+
const j = new URL('home', 'http://localhost');
39+
expect(j.href).toBe('http://localhost/home');
40+
// Insert / between Base and Path if missing
41+
const k = new URL('en-US/docs', 'https://developer.mozilla.org');
42+
expect(k.href).toBe('https://developer.mozilla.org/en-US/docs');
43+
44+
45+
46+
47+
1748
const url = new URL('https://username:[email protected]:8080/docs/path?query=testQuery&key=value#fragment');
1849

1950
expect(url.hash).toBe('#fragment');
@@ -25,64 +56,6 @@ describe('URL', function () {
2556
expect(url.port).toBe('8080');
2657
expect(url.search).toBe('?query=testQuery&key=value');
2758

28-
// Test searchParams parsing
29-
expect(url.searchParams.get('query')).toBe('testQuery');
30-
expect(url.searchParams.get('key')).toBe('value');
31-
});
32-
33-
it('should handle URLs without authentication correctly', () => {
34-
const url = new URL('https://reactnative.dev/docs');
35-
36-
expect(url.username).toBe('');
37-
expect(url.password).toBe('');
38-
});
39-
40-
it('should handle URLs without query parameters', () => {
41-
const url = new URL('https://reactnative.dev/docs');
42-
43-
expect(url.search).toBe('');
44-
expect(url.searchParams.toString()).toBe('');
45-
});
46-
47-
it('should handle URLs without a port', () => {
48-
const url = new URL('https://reactnative.dev/docs');
49-
50-
expect(url.port).toBe('');
51-
});
52-
53-
it('should handle URLs without a hash', () => {
54-
const url = new URL('https://reactnative.dev/docs');
55-
56-
expect(url.hash).toBe('');
57-
});
58-
59-
it('should handle URLs with relative paths correctly', () => {
60-
const base = new URL('https://developer.mozilla.org');
61-
62-
const url1 = new URL('/en-US/docs', base);
63-
expect(url1.href).toBe('https://developer.mozilla.org/en-US/docs');
64-
65-
const url2 = new URL('en-US/docs', base);
66-
expect(url2.href).toBe('https://developer.mozilla.org/en-US/docs');
67-
});
68-
69-
it('should support bare hosts and relative paths', () => {
70-
const url = new URL('home', 'http://localhost');
71-
expect(url.href).toBe('http://localhost/home');
72-
});
73-
74-
it('should correctly resolve full URLs when given a base URL', () => {
75-
const url = new URL('http://github.com', 'http://google.com');
76-
expect(url.href).toBe('http://github.com/');
77-
});
78-
79-
it('should insert / between base and path if missing', () => {
80-
const url = new URL('en-US/docs', 'https://developer.mozilla.org');
81-
expect(url.href).toBe('https://developer.mozilla.org/en-US/docs');
82-
});
8359

84-
it('should default pathname to "/" if no path is provided', () => {
85-
const url = new URL('https://example.com');
86-
expect(url.pathname).toBe('/');
8760
});
8861
});

0 commit comments

Comments
 (0)