-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.test.js
48 lines (42 loc) · 1.54 KB
/
main.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { describe, expect, test } from 'vitest';
import uppercase from './main.js';
describe('Uppercase Function Test', () => {
test('Should uppercase the first letter of each word correctly', () => {
//Arrange
const input = "this is the best test ive ever seen";
const expected = "This Is The Best Test Ive Ever Seen";
//Act
const actual = uppercase(input);
//Assert
expect(actual).toBe(expected);
})
test('Should throw error if input is not a string', () => {
//Arrange
const invalidInputs = [123, true, [], {}, null, undefined];
//Act
invalidInputs.forEach(input => {
//Assert
expect(() => uppercase(input)).toThrow('Input must be a string');
})
})
test('Should handle strings with mixed case', () => {
const input = "tHis Is A teSt";
const expected = "This Is A Test";
expect(uppercase(input)).toBe(expected);
});
test('Should handle strings with only spaces correctly', () => {
const input = " ";
const expected = " ";
expect(uppercase(input)).toBe(expected);
});
test('Should handle multiple spaces between words correctly', () => {
const input = "hello world";
const expected = "Hello World";
expect(uppercase(input)).toBe(expected);
});
test('Should handle strings with non-alpha characters correctly', () => {
const input = "hello $world *&* test";
const expected = "Hello $World *&* Test";
expect(uppercase(input)).toBe(expected);
});
})