Skip to content

Commit

Permalink
test(finance): fix tests for amount (#2702)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Mar 7, 2024
1 parent ccd7054 commit e1dc906
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions test/modules/finance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,8 @@ describe('finance', () => {

expect(amount).toBeTruthy();
expect(amount).toBeTypeOf('string');
expect(
+amount,
'the amount should be greater than 0'
).toBeGreaterThan(0);
expect(+amount, 'the amount should be less than 1001').toBeLessThan(
1001
);
expect(+amount).toBeGreaterThanOrEqual(0);
expect(+amount).toBeLessThanOrEqual(1000);
});

it('should use the default decimal location when not passing arguments', () => {
Expand All @@ -275,13 +270,15 @@ describe('finance', () => {
amount = faker.finance.amount(100, 100, 1);

expect(amount).toBeTruthy();
expect(amount, 'the amount should be equal 100.0').toBe('100.0');
expect(amount).toBe('100.0');
});

//TODO: add support for more currency and decimal options
it('should not include a currency symbol by default', () => {
const amount = faker.finance.amount();

expect(amount).toBeTruthy();
expect(amount).toBeTypeOf('string');
expect(
amount,
'The expected match should not include a currency symbol'
Expand All @@ -293,34 +290,24 @@ describe('finance', () => {

expect(amount).toBeTruthy();
expect(amount).toBeTypeOf('string');
expect(+amount, 'the amount should be less than 0').toBeLessThan(0);
expect(
+amount,
'the amount should be greater than -201'
).toBeGreaterThan(-201);
expect(+amount).toBeLessThanOrEqual(-1);
expect(+amount).toBeGreaterThanOrEqual(-200);
});

it('should handle argument dec', () => {
const amount = faker.finance.amount(100, 100, 1);

expect(amount).toBeTruthy();
expect(amount, 'the amount should be equal 100.0').toBe('100.0');
expect(amount).toBeTypeOf('string');
expect(amount).toBe('100.0');
});

it('should handle argument dec = 0', () => {
const amount = faker.finance.amount(100, 100, 0);

expect(amount).toBeTruthy();
expect(amount, 'the amount should be equal 100').toBe('100');
});

it('should return a string', () => {
const amount = faker.finance.amount(100, 100, 0);

expect(amount).toBeTruthy();
expect(amount, 'the amount type should be string').toBeTypeOf(
'string'
);
expect(amount).toBeTypeOf('string');
expect(amount).toBe('100');
});

it.each([false, undefined])(
Expand All @@ -335,7 +322,7 @@ describe('finance', () => {
autoFormat
);

expect(amount).toStrictEqual(number.toString());
expect(amount).toBe(number.toString());
}
);

Expand Down

0 comments on commit e1dc906

Please sign in to comment.