From 7b3f297bbd13af401f0791c7a304e6dfe403afd4 Mon Sep 17 00:00:00 2001 From: Sylwia Leung Date: Tue, 30 Jun 2026 13:24:59 +0200 Subject: [PATCH] Wrote tests for arrayReverse function --- src/arrayReverse.test.js | 54 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/src/arrayReverse.test.js b/src/arrayReverse.test.js index 6e7ca36..57f0764 100644 --- a/src/arrayReverse.test.js +++ b/src/arrayReverse.test.js @@ -1,18 +1,62 @@ 'use strict'; -describe(`Function 'arrayReverse':`, () => { - const arrayReverse = require('./arrayReverse'); +const arrayReverse = require('./arrayReverse'); +describe(`Function 'arrayReverse':`, () => { it(`should be declared`, () => { expect(arrayReverse).toBeInstanceOf(Function); }); - it(`should return an array`, () => {}); + it.each([[['Mate', 'Academy']], [[]], [['Hello!', '123', 'test_case']]])( + `should return an array`, + (input) => { + const result = arrayReverse(input); + + expect(Array.isArray(result)).toBe(true); + }, + ); - it(`should return an empty string - if original array consists of an empty string`, () => { + it(`should return reversed input`, () => { expect(arrayReverse(['Mate', 'Academy'])).toEqual(['ymed', 'acAetaM']); }); // write more tests here + it(`should return reversed input`, () => { + expect(arrayReverse(["What's", 'good,', 'my', 'Dear', 'Mate'])).toEqual([ + 'etaMra', + 'eDym,', + 'do', + "ogs'", + 'tahW', + ]); + }); + + it.each([ + [[]], + [['Abc', 'Defg', 'Hijkl', 'Mnopqr']], + [['The quick brown fox jumps over the lazy dog']], + ])(`should return a value with the same length as the input`, (input) => { + const result = arrayReverse(input); + + expect(result.length).toEqual(input.length); + }); + + it(`should return an empty string if original array consists of an empty string`, () => { + expect(arrayReverse([''])).toEqual(['']); + }); + + it.each([ + [['Hello!', '123', 'test_case', 'a b c']], + [['#JS2024', '', 'multi word', "don't", ' ']], + [[' spacje ', 'CamelCase', '42!', 'ąęół']], + ])( + `should return an array of values with the same length as input values`, + (input) => { + const result = arrayReverse(input); + + result.forEach((element, index) => { + expect(element.length).toBe(input[index].length); + }); + }, + ); });