Create function test helpers

This commit is contained in:
2023-11-21 17:45:27 +07:00
parent 17edbc8c36
commit 609b9abd52
3 changed files with 64 additions and 0 deletions
@@ -0,0 +1,9 @@
import { formatCurrency } from '@helper/helper';
describe('Helpers function test', () => {
test('Format number to currency format', () => {
const result = formatCurrency(5000);
expect(result).toEqual('$5,000.00');
});
});
@@ -0,0 +1,44 @@
import { REGEX } from '@constant/commons';
import { isValidDiscount, isValidRegex, isValidString } from '@helper/validators';
describe('Check value is valid phone', () => {
test('Is valid phone', () => {
const result = isValidRegex(new RegExp(REGEX.PHONE), '0327212321');
expect(result).toEqual(true);
});
test('Is invalid phone', () => {
const result = isValidRegex(new RegExp(REGEX.PHONE), '0327212321Abc');
expect(result).toEqual(false);
});
});
describe('Check value is valid discount', () => {
test('Is valid discount', () => {
const result = isValidDiscount(23);
expect(result).toEqual(true);
});
test('Is invalid discount', () => {
const result = isValidDiscount(101);
expect(result).toEqual(false);
});
});
describe('Check value is valid string', () => {
test('Is valid string', () => {
const result = isValidString('Phan Huu Loi');
expect(result).toEqual(true);
});
test('Is valid string', () => {
const result = isValidString('Phan');
expect(result).toEqual(false);
});
});
@@ -0,0 +1,11 @@
import { useRooms } from '@hook/rooms/useRooms';
import { renderHook, waitFor } from '@testing-library/react';
describe('CRUD Room testing', () => {
test('Fetch room data', async () => {
const { result } = renderHook(() => useRooms());
const { rooms } = result.current;
await waitFor(() => expect(rooms?.length).toBeGreaterThan(0))
})
})