-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtdd.test.js
30 lines (25 loc) · 920 Bytes
/
tdd.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
import { describe, expect, it } from 'vitest';
import { makeNewTodo } from './new-todo.js';
describe('todo object validation', () => {
it('Function returns new todo', () => {
// Arrange ...
const todoText = 'study javascript';
// Act ...
const result = makeNewTodo(todoText);
// Assert ...
expect(typeof result.createdAt).toBe('string');
expect(typeof result.done).toBe('boolean');
expect(typeof result.id).toBe('number');
expect(typeof result.text).toBe('string');
});
it('Passing in any arguments except a string throws an error', () => {
// Arrange ...
function expectError() {
makeNewTodo({}); // passing in an object into the function
};
// Act and assert ...
expect(expectError).toThrowError(
/^Function argument is not a string$/,
);
});
})