Skip to content

Commit ae273f4

Browse files
committed
Mock fetch for other component tests.
1 parent 213d7ba commit ae273f4

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

tests/js/component/messageSender.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { send } from "../../../django_unicorn/static/js/messageSender.js";
55

66
test.cb("click on internal element", (t) => {
77
const html = `
8-
<input type="hidden" name="csrfmiddlewaretoken" value="vte8BO6vgh1t7zUMDm8fdhpDNV62Hfc1fibo0a5doKc7DE0LybjTw5UNS6YMaYDa">
9-
<div unicorn:id="5jypjiyb" unicorn:name="text-inputs" unicorn:checksum="GXzew3Km">
8+
<input type="hidden" name="csrfmiddlewaretoken" value="asdf">
9+
<div unicorn:id="5jypjiyb" unicorn:name="text-inputs" unicorn:checksum="GXzew3Km">
1010
<input unicorn:model='name'></input>
1111
<button unicorn:click='test()'><span id="clicker">Click</span></button>
12-
</div>`;
12+
</div>
13+
`;
1314

1415
const component = getComponent(html);
1516

tests/js/utils.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { JSDOM } from "jsdom";
2+
import fetchMock from "fetch-mock";
23
import { Element } from "../../django_unicorn/static/js/element.js";
34
import { Component } from "../../django_unicorn/static/js/component.js";
45

@@ -65,9 +66,14 @@ export function getComponent(html, id, name, data) {
6566
<div unicorn:id="5jypjiyb" unicorn:name="text-inputs" unicorn:checksum="GXzew3Km">
6667
<input unicorn:model='name'></input>
6768
<button unicorn:click='name="world"'></button>
68-
</div>`;
69+
</div>
70+
`;
6971
}
7072

73+
html = `
74+
<input type="hidden" name="csrfmiddlewaretoken" value="asdf">${html}
75+
`;
76+
7177
if (typeof id === "undefined") {
7278
id = "5jypjiyb";
7379
}
@@ -92,5 +98,15 @@ export function getComponent(html, id, name, data) {
9298
window: { location: { href: "" } },
9399
});
94100

101+
const res = {
102+
id: "",
103+
dom: "",
104+
data: {},
105+
errors: {},
106+
redirect: {},
107+
return: {},
108+
};
109+
global.fetch = fetchMock.sandbox().mock().post("/test/text-inputs", res);
110+
95111
return component;
96112
}

0 commit comments

Comments
 (0)