Skip to content

Commit

Permalink
[react-native-url-polyfill] New definition (#4246)
Browse files Browse the repository at this point in the history
* add initial definition

* add some api tests
  • Loading branch information
Brianzchen committed Feb 4, 2022
1 parent d576e7d commit edaf30f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
@@ -0,0 +1,13 @@
declare module 'react-native-url-polyfill' {
import typeof { URL as NativeURL, URLSearchParams as NativeURLSearchParams } from 'url';

declare export var URL: NativeURL;

declare export var URLSearchParams: NativeURLSearchParams;

declare export function setupURLPolyfill(): void;
}

declare module 'react-native-url-polyfill/auto' {
declare module.exports: void;
}
@@ -0,0 +1,29 @@
// @flow
import { describe, it } from 'flow-typed-test';
import { setupURLPolyfill, URL, URLSearchParams } from 'react-native-url-polyfill';
import auto from 'react-native-url-polyfill/auto';

describe('react-native-url-polyfill', () => {
it('simple usage', () => {
// It's an auto running script
(auto: void);
});

it('flexible usage', () => {
setupURLPolyfill();

// $FlowExpectedError[extra-arg] takes no args
setupURLPolyfill('test');
});

it('convenient usage', () => {
const url = new URL('https://github.com');
const searchParams = new URLSearchParams('q=GitHub');

// Has the same methods as node `url`
// $FlowExpectedError[extra-arg]
url.toJSON('test');
// $FlowExpectedError[incompatible-call]
searchParams.delete();
});
});

0 comments on commit edaf30f

Please sign in to comment.