title: Jest - Map through an Array of Items and test their Values
body: <p>I have a simple Utility Function. It takes an Enum, and Transform's it to an Array of Objects shaped as <code>{label: string, value:string}</code>.</p>
  
  <p>Here is the Function as well as the Interface it uses:</p>
  
  <pre><code>export interface ISelectOption {
    value: string;
    label: string;
    selected?: boolean;
  }
  
  const transformEnumToISelectArray = (object: object): ISelectOption[] =&gt;
    Object.keys(object).map(value =&gt; ({
      label: value,
      value
    }));
  
  export default transformEnumToISelectArray;
  </code></pre>
  
  <p>I have a repetitive Test. Basically, I check if the output of label/value, is what is expected, if I provide a Enum. Here is the test, that it is currently working:</p>
  
  <pre><code>import transformEnumToISelectArray from '../transformEnumToISelectArray';
  import ISelectOption from '../../interfaces/ISelectOption';
  
  describe('transformEnumToISelectArray', () =&gt; {
    enum mockEnum {
      FIELD1 = 'FIELD1',
      FIELD2 = 'FIELD2',
      FIELD3 = 'FIELD3'
    }
  
    let expectedResult: ISelectOption[] = [];
    let nonExpectedResult: ISelectOption[] = [];
  
    describe('ExpectedResults', () =&gt; {
      beforeEach(() =&gt; {
        expectedResult = [
          {
            label: 'FIELD1',
            value: 'FIELD1'
          },
          {
            label: 'FIELD2',
            value: 'FIELD2'
          },
          {
            label: 'FIELD3',
            value: 'FIELD3'
          }
        ];
      });
      it('should return an Array of ISelectOption shaped Object with correct `label` and `value`', () =&gt; {
        const response = transformEnumToISelectArray(mockEnum);
        expect(response[0].label).toEqual(expectedResult[0].label);
        expect(response[1].label).toEqual(expectedResult[1].label);
        expect(response[2].label).toEqual(expectedResult[2].label);
        expect(response[0].value).toEqual(expectedResult[0].value);
        expect(response[1].value).toEqual(expectedResult[1].value);
        expect(response[2].value).toEqual(expectedResult[2].value);
      });
    });
  });
  </code></pre>
  
  <p>Please ignore the <code>beforeEach()</code>, I have more tests, but I ommited them. My problem and this is just an optimization here, is that I want to make it better. So, I though I would <code>map</code> through the Array of <code>response</code> and <code>expectedResult</code> using Enzymes's <code>.map(fn) =&gt; Array&lt;Any&gt;</code>.</p>
  
  <p>This is what I did:</p>
  
  <pre><code>expect(response.map(index =&gt; response[index].lable)).toEqual(
          expectedResult.map(index =&gt; expectedResult[index].label)
        );
  </code></pre>
  
  <p>But I get the following:</p>
  
  <pre><code>Type 'ISelectOption' cannot be used as an index type.ts(2538)
  </code></pre>
  
  <p>Does anyone understand this. Do I need to spacifiy an index Property on my ISelectOption interface for this to work? Any Ideas?</p>