import { flatten } from './flatten'; describe('flatten', () => { let result; let inputValue; beforeEach(() => result = flatten(inputValue)); describe('when input value is not Array', () => { describe.each` input | type ${undefined} | ${undefined} ${null} | ${null} ${123} | ${'number'} ${'iHopeYouWillSeeIt'} | ${'string'} ${{ a: 1 }} | ${'object'} `('when input value is $type', ({ input, type }) => { beforeAll(() => inputValue = input); it('returns "undefined"', () => { expect(result).toBeUndefined(); }); }); }); describe('when input value is Array', () => { describe.each` input | comment | expectedValue ${[]} | ${'empty'} | ${[]} ${[1, 2, 3]} | ${'flat'} | ${[1, 2, 3]} ${[1, [2]]} | ${'not a flat'} | ${[1, 2]} ${[1, [[2]]]} | ${'not a flat'} | ${[1, 2]} `('when array is $comment', ({ input, comment, expectedValue }) => { beforeAll(() => inputValue = input); it(`returns flattened array`, () => { expect(result).toEqual(expectedValue); }); }); }); });