title: Javascript Testing With Unique ID's
body: <p>I am kinda new to testing javascript and I was wondering what is the best way to go about testing something where a unique ID is generated.</p>
  
  <p>EDIT:</p>
  
  <p>I don't really want to test the ID I want to make sure that the action returns the right results when the createQuestion function is called. But the test will fail because the ID will never match since it is generated in the function.</p>
  
  <p>My current code looks like this.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//------- Action Creator --------//
  
  export const createQuestion = function (inputType) {
    const hasOptions = /radio/g.test(inputType);
    return {
      type: types.CREATE_QUESTION,
      question: {
        id: uuid.v1(),
        priority: null,
        title: null,
        tip: null,
        required: false,
        isSaved: false,
        hasOptions: hasOptions,
        input: {
          type: inputType,
          options: []
        }
      }
    };
  };
  
  
  //------- TESTS --------//
  test('Question Actions', nest =&gt; {
  
    nest.test('Create Question', function (assert) {
      const msg = 'Questions was Created';
  
      const question = {
        id: 1,
        priority: null,
        title: null,
        tip: null,
        required: false,
        isSaved: false,
        hasOptions: false,
        input: {
          type: 'text',
          options: []
        }
      };
  
      const expectedAction = {
        type: types.CREATE_QUESTION,
        question
      };
  
  
      const actualAction = actions.createQuestion('text');
      assert.deepEqual(actualAction, expectedAction, msg);
      assert.end();
    });</code></pre>
  </div>
  </div>
  </p>
  
  <p>Since the Unique Id is generated in the Action Creator it is impossible to mock unless I change the ID after the function returns with the action.</p>
  
  <p>With something like this</p>
  
  <pre><code>const changeUUID = obj =&gt; {
    const newobj = {...obj};
    newobj.question.id = 1;
    return newobj;
  };
  </code></pre>