Skip to content
Open
Changes from 1 commit
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
65 changes: 62 additions & 3 deletions src/restoreNames.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,70 @@
'use strict';

describe('restoreNames', () => {
// const { restoreNames } = require('./restoreNames');
const { restoreNames } = require('./restoreNames');

it('should ', () => {
it('should update firstname field', () => {
const users = [
{
firstName: undefined,
lastName: 'Holy',
fullName: 'Jack Holy',
},
];

restoreNames(users);

expect(users).toEqual([
{
firstName: 'Jack',
lastName: 'Holy',
fullName: 'Jack Holy',
},
]);
});

it('should add firstname field if not exist', () => {
const users = [
{
lastName: 'Adams',
fullName: 'Mike Adams',
},
];

restoreNames(users);

expect(users).toEqual([
{
firstName: 'Mike',
lastName: 'Adams',
fullName: 'Mike Adams',
},
]);
});

it('should return {} if users.length = 0', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test description is a bit misleading. The requirements state that the restoreNames function should not return anything. A description like 'should handle an empty array without errors' would be more accurate.

const users = [];

restoreNames(users);

expect(users).toEqual([]);
});

// write tests here
it(`should return initial result if firstname isn't empty`, () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the test for an empty array, this description mentions 'return'. It would be clearer to describe what happens to the input data, for example: 'should not change users who already have a firstName'.

const users = [
{
firstName: 'Mike',
lastName: 'Adams',
},
];

restoreNames(users);

expect(users).toEqual([
{
firstName: 'Mike',
lastName: 'Adams',
},
]);
});
});