-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
33 lines (26 loc) · 802 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import test from 'ava';
import {HTTPError} from 'ky';
import npmEmail from './index.js';
test('invalid input', async t => {
await t.throwsAsync(npmEmail(1), {message: 'Username required'});
});
test('valid username', async t => {
t.is(await npmEmail('sindresorhus'), '[email protected]');
t.is(await npmEmail('vdemedes'), '[email protected]');
});
test('non-existent user', async t => {
t.is(await npmEmail('nnnope'), undefined);
});
test.serial('handles 404', async t => {
const {fetch} = globalThis;
globalThis.fetch = async () => {
throw new HTTPError(
new Response('', {status: 404, statusText: 'Not Found'}),
);
};
await t.throwsAsync(
npmEmail('nnnope'),
{message: 'User `nnnope` could not be found', code: 'ERR_NO_NPM_USER'},
);
globalThis.fetch = fetch;
});