-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
33 lines (28 loc) · 1015 Bytes
/
index.test.js
File metadata and controls
33 lines (28 loc) · 1015 Bytes
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
const dotenv = require('dotenv');
const argparse = require('argparse');
const envflags = require('./index');
it('should throw an error if argparse instance is not given', () => {
expect(() => {
envflags({ API: 'somekeyofapi', VALUE: 'somevalue' });
}).toThrow();
});
it('should result in identical result from argparse', () => {
const parser = argparse.ArgumentParser();
const parser2 = argparse.ArgumentParser();
expect(envflags(parser2, { PORT: 8080, URL: 'https://mydomain.com' })).toBeInstanceOf(
argparse.ArgumentParser,
);
});
it('should match value of argparse', () => {
const parser = argparse.ArgumentParser();
parser.addArgument(['-i', '--ignore'], {
defaultValue: true,
});
parser.addArgument(['-p', '--port'], {
defaultValue: 8080,
});
const argValues = parser.parseArgs();
const parser2 = argparse.ArgumentParser();
const envFlagValues = envflags(parser2, { PORT: 8080, ignore: true }).parseArgs();
expect(envFlagValues).toMatchObject(argValues);
});