Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(finance): fix tests for amount #2702

Merged
merged 5 commits into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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