43 lines
994 B
JavaScript
43 lines
994 B
JavaScript
const { greet, add, isValidEmail } = require('../src/index');
|
|
|
|
describe('greet function', () => {
|
|
test('greets with default name', () => {
|
|
expect(greet()).toBe('Hello, World!');
|
|
});
|
|
|
|
test('greets with custom name', () => {
|
|
expect(greet('GitLink')).toBe('Hello, GitLink!');
|
|
});
|
|
|
|
test('handles empty string', () => {
|
|
expect(greet('')).toBe('Hello, !');
|
|
});
|
|
});
|
|
|
|
describe('add function', () => {
|
|
test('adds two positive numbers', () => {
|
|
expect(add(2, 3)).toBe(5);
|
|
});
|
|
|
|
test('adds negative numbers', () => {
|
|
expect(add(-1, -1)).toBe(-2);
|
|
});
|
|
|
|
test('adds zero', () => {
|
|
expect(add(0, 5)).toBe(5);
|
|
});
|
|
});
|
|
|
|
describe('isValidEmail function', () => {
|
|
test('validates correct email', () => {
|
|
expect(isValidEmail('test@example.com')).toBe(true);
|
|
});
|
|
|
|
test('rejects email without @', () => {
|
|
expect(isValidEmail('test.example.com')).toBe(false);
|
|
});
|
|
|
|
test('rejects empty email', () => {
|
|
expect(isValidEmail('')).toBe(false);
|
|
});
|
|
}); |