<commit_before>import expect from 'expect';
import { PUSH, POP } from '../Actions';
import execSteps from './execSteps';

function describeGo(createHistory) {
  describe('goBack', function () {
    var history, unlisten;
    beforeEach(function () {
      history = createHistory();
    });

    afterEach(function () {
      if (unlisten)
        unlisten();
    });

    it('calls change listeners with the previous location', function (done) {
      var steps = [
        function (location) {
          expect(location.pathname).toEqual('/');
          expect(location.search).toEqual('');
          expect(location.state).toEqual(null);
          expect(location.action).toEqual(POP);

          history.pushState({ the: 'state' }, '/one?the=query');
        },
        function (location) {
          expect(location.pathname).toEqual('/one');
          expect(location.search).toEqual('?the=query');
          expect(location.state).toEqual({ the: 'state' });
          expect(location.action).toEqual(PUSH);

          history.goBack();
        },
        function (location) {
          expect(location.pathname).toEqual('/');
          expect(location.search).toEqual('');
          expect(location.state).toEqual(null);
          expect(location.action).toEqual(POP);
        }
      ];

      unlisten = history.listen(execSteps(steps, done));
    });
  });

  describe('goForward', function () {
    var history, unlisten;
    beforeEach(function () {
      history = createHistory();
    });

    afterEach(function () {
      if (unlisten)
        unlisten();
    });

    it('calls change listeners with the next location', function (done) {
      var steps = [
        function (location) {
          expect(location.pathname).toEqual('/');
          expect(location.search).toEqual('');
          expect(location.state).toEqual(null);
          expect(location.action).toEqual(POP);

          history.pushState({ the: 'state' }, '/one?the=query');
        },
        function (location) {
          expect(location.pathname).toEqual('/one');
          expect(location.search).toEqual('?the=query');
          expect(location.state).toEqual({ the: 'state' });
          expect(location.action).toEqual(PUSH);

          history.goBack();
        },
        function (location) {
          expect(location.pathname).toEqual('/');
          expect(location.search).toEqual('');
          expect(location.state).toEqual(null);
          expect(location.action).toEqual(POP);

          history.goForward();
        },
        function (location) {
          expect(location.pathname).toEqual('/one');
          expect(location.search).toEqual('?the=query');
          expect(location.state).toEqual({ the: 'state' });
          expect(location.action).toEqual(POP);
        }
      ];

      unlisten = history.listen(execSteps(steps, done));
    });
  });
}

export default describeGo;<commit_msg>Reduce code duplication<commit_after>import expect from 'expect';
import { PUSH, POP } from '../Actions';
import execSteps from './execSteps';

function describeGo(createHistory) {
  describe('go', function () {
    var history, unlisten;
    beforeEach(function () {
      history = createHistory();
    });

    afterEach(function () {
      if (unlisten)
        unlisten();
    });

    describe('back', function () {
      it('calls change listeners with the previous location', function (done) {
        var steps = [
          function (location) {
            expect(location.pathname).toEqual('/');
            expect(location.search).toEqual('');
            expect(location.state).toEqual(null);
            expect(location.action).toEqual(POP);

            history.pushState({ the: 'state' }, '/one?the=query');
          },
          function (location) {
            expect(location.pathname).toEqual('/one');
            expect(location.search).toEqual('?the=query');
            expect(location.state).toEqual({ the: 'state' });
            expect(location.action).toEqual(PUSH);

            history.goBack();
          },
          function (location) {
            expect(location.pathname).toEqual('/');
            expect(location.search).toEqual('');
            expect(location.state).toEqual(null);
            expect(location.action).toEqual(POP);
          }
        ];

        unlisten = history.listen(execSteps(steps, done));
      });
    });

    describe('forward', function () {
      it('calls change listeners with the next location', function (done) {
        var steps = [
          function (location) {
            expect(location.pathname).toEqual('/');
            expect(location.search).toEqual('');
            expect(location.state).toEqual(null);
            expect(location.action).toEqual(POP);

            history.pushState({ the: 'state' }, '/one?the=query');
          },
          function (location) {
            expect(location.pathname).toEqual('/one');
            expect(location.search).toEqual('?the=query');
            expect(location.state).toEqual({ the: 'state' });
            expect(location.action).toEqual(PUSH);

            history.goBack();
          },
          function (location) {
            expect(location.pathname).toEqual('/');
            expect(location.search).toEqual('');
            expect(location.state).toEqual(null);
            expect(location.action).toEqual(POP);

            history.goForward();
          },
          function (location) {
            expect(location.pathname).toEqual('/one');
            expect(location.search).toEqual('?the=query');
            expect(location.state).toEqual({ the: 'state' });
            expect(location.action).toEqual(POP);
          }
        ];

        unlisten = history.listen(execSteps(steps, done));
      });
    });
  });
}

export default describeGo;
{'fraction_non_alphanumeric': 0.1576685006877579, 'fraction_numerical': 0.0, 'mean_word_length': 2.25517627308338, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6864458', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1555, 'n_words': 251}