summaryrefslogtreecommitdiff
path: root/history/modules/__tests__/TestSequences/DenyGoForward.js
blob: fa27a933d54fd37993bf95f7dafd3844dde7f0cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import expect from 'expect';

import execSteps from './execSteps.js';

export default function(history, done) {
  let unblock;
  const steps = [
    location => {
      expect(location).toMatchObject({
        pathname: '/'
      });

      history.push('/home');
    },
    (location, action) => {
      expect(action).toBe('PUSH');
      expect(location).toMatchObject({
        pathname: '/home'
      });

      history.goBack();
    },
    (location, action) => {
      expect(action).toBe('POP');
      expect(location).toMatchObject({
        pathname: '/'
      });

      unblock = history.block(nextLocation => {
        expect(nextLocation).toMatchObject({
          pathname: '/home'
        });

        return 'Are you sure?';
      });

      history.goForward();
    },
    (location, action) => {
      expect(action).toBe('POP');
      expect(location).toMatchObject({
        pathname: '/'
      });

      unblock();
    }
  ];

  execSteps(steps, history, done);
}