/
Redirect-test.js
68 lines (61 loc) · 1.73 KB
/
Redirect-test.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React from "react";
import ReactDOM from "react-dom";
import { MemoryRouter, Redirect, Route, Switch } from "react-router";
import { createLocation } from "history";
import renderStrict from "./utils/renderStrict";
describe("A <Redirect>", () => {
const node = document.createElement("div");
afterEach(() => {
ReactDOM.unmountComponentAtNode(node);
});
describe("that always renders", () => {
it("doesn't break / throw when rendered with string `to`", () => {
expect(() => {
renderStrict(
<MemoryRouter>
<Redirect to="go-out" />
</MemoryRouter>,
node
);
}).not.toThrow();
});
it("doesn't break / throw when rendered with location `to`", () => {
const to = createLocation("/go-out?search=foo#hash");
expect(() => {
renderStrict(
<MemoryRouter>
<Redirect to={to} />
</MemoryRouter>,
node
);
}).not.toThrow();
});
});
describe("inside a <Switch>", () => {
it("automatically interpolates params", () => {
let params;
renderStrict(
<MemoryRouter initialEntries={["/users/mjackson/messages/123"]}>
<Switch>
<Redirect
from="/users/:username/messages/:messageId"
to="/:username/messages/:messageId"
/>
<Route
path="/:username/messages/:messageId"
render={({ match }) => {
params = match.params;
return null;
}}
/>
</Switch>
</MemoryRouter>,
node
);
expect(params).toMatchObject({
username: "mjackson",
messageId: "123"
});
});
});
});