Skip to content
Open
Changes from all commits
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
37 changes: 34 additions & 3 deletions src/arrayReverse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,44 @@ describe(`Function 'arrayReverse':`, () => {
});

it(`should return an array`, () => {

expect(arrayReverse(['Mate', 'Academy'])).toBeInstanceOf(Array);
expect(arrayReverse(['Mate', 'Academy'])).toHaveLength(2);
Comment on lines +11 to +12

Choose a reason for hiding this comment

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

These are good assertions! However, you are calling the arrayReverse function twice here with the same arguments. It's a better practice to call the function only once, save its result to a variable, and then perform all your checks on that variable. This makes the test more efficient and often easier to read.

});

it(`should return an empty string
if original array consists of an empty string`, () => {
expect(arrayReverse(['Mate', 'Academy'])).toEqual(['ymed', 'acAetaM']);
expect(arrayReverse(['', 'am'])).toEqual(['', 'ma']);
expect(arrayReverse(['am', ''])).toEqual(['ma', '']);
expect(arrayReverse(['', ''])).toEqual(['', '']);
});

it(`should does not change length of the strings`, () => {
const words = ['I', 'am', 'a', 'student!'];

expect(words[0]).toHaveLength(1);
expect(words[1]).toHaveLength(2);
expect(words[2]).toHaveLength(1);
expect(words[3]).toHaveLength(8);

const actual = arrayReverse(words);
const expected = ['!', 'tn', 'e', 'dutsamaI'];

expect(actual[0]).toHaveLength(1);
expect(actual[1]).toHaveLength(2);
expect(actual[2]).toHaveLength(1);
expect(actual[3]).toHaveLength(8);
expect(actual).toEqual(expected);
});

// write more tests here
it(`should work properly with diff arrays`, () => {
expect(arrayReverse(['Hell0'])).toEqual(['0lleH']);

expect(arrayReverse(['Mate', 'Academy'])).toEqual(['ymed', 'acAetaM']);

expect(arrayReverse(['Hi', 'Mate', 'Academy']))
.toEqual(['ym', 'edac', 'AetaMiH']);

expect(arrayReverse(['I', 'am', 'a', 'student!']))
.toEqual(['!', 'tn', 'e', 'dutsamaI']);
});
});