Skip to content

Commit

Permalink
Add additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xxczaki committed Aug 24, 2019
1 parent 3d48551 commit c018c96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions test/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const rates = {
const cashify = new Cashify({base: 'EUR', rates});

test('basic conversion', t => {
t.is(cashify.convert(12, {from: 'USD', to: 'GBP'}), 9.857142857142858);
t.is(cashify.convert(12, {from: 'USD', to: 'GBP'}), 9.857142857142856);
});

test('`from` equals `base`', t => {
t.is(cashify.convert(10, {from: 'EUR', to: 'GBP'}), 9.2);
});

test('`to` equals `base`', t => {
t.is(cashify.convert(10, {from: 'GBP', to: 'EUR'}), 10.869565217391305);
t.is(cashify.convert(10, {from: 'GBP', to: 'EUR'}), 10.869565217391303);
});

test('`from` equals `to`', t => {
Expand All @@ -41,3 +41,11 @@ test('`rates` without `base` currency', t => {

t.is(cashify.convert(10, {from: 'EUR', to: 'GBP'}), 9.2);
});

test('`rates` object does not contain either `from` or `to` currency', t => {
const error = t.throws(() => {
cashify.convert(10, {from: 'CHF', to: 'EUR'});
}, Error);

t.is(error.message, '`rates` object does not contain either `from` or `to` currency!');
});
12 changes: 10 additions & 2 deletions test/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const rates = {
};

test('basic conversion', t => {
t.is(convert(12, {from: 'USD', to: 'GBP', base: 'EUR', rates}), 9.857142857142858);
t.is(convert(12, {from: 'USD', to: 'GBP', base: 'EUR', rates}), 9.857142857142856);
});

test('`from` equals `base`', t => {
t.is(convert(10, {from: 'EUR', to: 'GBP', base: 'EUR', rates}), 9.2);
});

test('`to` equals `base`', t => {
t.is(convert(10, {from: 'GBP', to: 'EUR', base: 'EUR', rates}), 10.869565217391305);
t.is(convert(10, {from: 'GBP', to: 'EUR', base: 'EUR', rates}), 10.869565217391303);
});

test('`from` equals `to`', t => {
Expand All @@ -35,3 +35,11 @@ test('`rates` without `base` currency', t => {

t.is(convert(10, {from: 'EUR', to: 'GBP', base: 'EUR', rates}), 9.2);
});

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);

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

0 comments on commit c018c96

Please sign in to comment.