Skip to content

Commit

Permalink
Update parsing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xxczaki committed Feb 22, 2020
1 parent a205aa5 commit 40c2201
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions test/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,20 @@ test('basic parsing (float)', t => {

test('full parsing (integer)', t => {
t.is(cashify.convert('$12 USD TO GBP'), 9.857142857142856);
t.is(cashify.convert('$12 USD IN GBP'), 9.857142857142856);
t.is(cashify.convert('$12 USD AS GBP'), 9.857142857142856);
});

test('full parsing (float)', t => {
t.is(cashify.convert('1.23 gbp to eur'), 1.3369565217391304);
t.is(cashify.convert('1.23 gbp in eur'), 1.3369565217391304);
t.is(cashify.convert('1.23 gbp as eur'), 1.3369565217391304);
});

test('`from` is not defined', t => {
const error = t.throws(() => {
cashify.convert(10, {to: 'EUR'});
}, Error);
}, {instanceOf: Error});

t.is(error.message, 'Please specify the `from` and/or `to` currency or use parsing!');
});
Expand All @@ -73,15 +77,15 @@ test('`rates` without `base` currency', t => {
test('`rates` object does not contain either `from` or `to` currency', t => {
const error = t.throws(() => {
cashify.convert(10, {from: 'CHF', to: 'EUR'});
}, Error);
}, {instanceOf: Error});

t.is(error.message, '`rates` object does not contain either `from` or `to` currency!');
});

test('parsing without a correct amount', t => {
const error = t.throws(() => {
cashify.convert('');
}, Error);
}, {instanceOf: Error});

t.is(error.message, 'Could not parse the `amount` argument. Make sure it includes at least a valid amount.');
});
10 changes: 7 additions & 3 deletions test/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,20 @@ test('basic parsing (float)', t => {

test('full parsing (integer)', t => {
t.is(convert('$12 USD TO GBP', {base: 'EUR', rates}), 9.857142857142856);
t.is(convert('$12 USD IN GBP', {base: 'EUR', rates}), 9.857142857142856);
t.is(convert('$12 USD AS GBP', {base: 'EUR', rates}), 9.857142857142856);
});

test('full parsing (float)', t => {
t.is(convert('1.23 gbp to eur', {base: 'USD', rates}), 1.3369565217391304);
t.is(convert('1.23 gbp in eur', {base: 'USD', rates}), 1.3369565217391304);
t.is(convert('1.23 gbp as eur', {base: 'USD', rates}), 1.3369565217391304);
});

test('`from` is not defined', t => {
const error = t.throws(() => {
convert(10, {to: 'EUR', base: 'USD', rates});
}, Error);
}, {instanceOf: Error});

t.is(error.message, 'Please specify the `from` and/or `to` currency or use parsing!');
});
Expand All @@ -67,15 +71,15 @@ test('`rates` without `base` currency', t => {
test('`rates` object does not contain either `from` or `to` currency', t => {
const error = t.throws(() => {
convert(10, {from: 'CHF', to: 'EUR', base: 'EUR', rates});
}, Error);
}, {instanceOf: Error});

t.is(error.message, '`rates` object does not contain either `from` or `to` currency!');
});

test('parsing without a correct amount', t => {
const error = t.throws(() => {
convert('', {base: 'EUR', rates});
}, Error);
}, {instanceOf: Error});

t.is(error.message, 'Could not parse the `amount` argument. Make sure it includes at least a valid amount.');
});

0 comments on commit 40c2201

Please sign in to comment.