mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 21:00:57 +00:00
Enable and apply ESLint Jest rules (#3270)
Jest was in the plugin array of the ESLint configuration, but no rules
were enabled. So ESLint hasn't checked any Jest rules yet.
So I activated the recommended Jest rules and added a few more. Then I
fixed the issues (mostly automatically). I have deactivated the rules
"jest/expect-expect" and "jest/no-done-callback" for the time being, as
they would have entailed major changes. I didn't want to make the PR too
big.
I'm not a Jest expert, but the changes so far look good to me. What do
you think of that @khassel? 🙂
This commit is contained in:
committed by
GitHub
parent
679a413788
commit
7098f1e41f
@@ -35,43 +35,43 @@ describe("server_functions tests", () => {
|
||||
};
|
||||
});
|
||||
|
||||
test("Calls correct URL once", async () => {
|
||||
it("Calls correct URL once", async () => {
|
||||
const urlToCall = "http://www.test.com/path?param1=value1";
|
||||
request.url = `/cors?url=${urlToCall}`;
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][0]).toBe(urlToCall);
|
||||
});
|
||||
|
||||
test("Forewards Content-Type if json", async () => {
|
||||
it("Forewards Content-Type if json", async () => {
|
||||
fetchResponseHeadersGet.mockImplementation(() => "json");
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchResponseHeadersGet.mock.calls.length).toBe(1);
|
||||
expect(fetchResponseHeadersGet.mock.calls).toHaveLength(1);
|
||||
expect(fetchResponseHeadersGet.mock.calls[0][0]).toBe("Content-Type");
|
||||
|
||||
expect(corsResponse.set.mock.calls.length).toBe(1);
|
||||
expect(corsResponse.set.mock.calls).toHaveLength(1);
|
||||
expect(corsResponse.set.mock.calls[0][0]).toBe("Content-Type");
|
||||
expect(corsResponse.set.mock.calls[0][1]).toBe("json");
|
||||
});
|
||||
|
||||
test("Forewards Content-Type if xml", async () => {
|
||||
it("Forewards Content-Type if xml", async () => {
|
||||
fetchResponseHeadersGet.mockImplementation(() => "xml");
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchResponseHeadersGet.mock.calls.length).toBe(1);
|
||||
expect(fetchResponseHeadersGet.mock.calls).toHaveLength(1);
|
||||
expect(fetchResponseHeadersGet.mock.calls[0][0]).toBe("Content-Type");
|
||||
|
||||
expect(corsResponse.set.mock.calls.length).toBe(1);
|
||||
expect(corsResponse.set.mock.calls).toHaveLength(1);
|
||||
expect(corsResponse.set.mock.calls[0][0]).toBe("Content-Type");
|
||||
expect(corsResponse.set.mock.calls[0][1]).toBe("xml");
|
||||
});
|
||||
|
||||
test("Sends correct data from response", async () => {
|
||||
it("Sends correct data from response", async () => {
|
||||
const responseData = "some data";
|
||||
fetchResponseHeadersText.mockImplementation(() => responseData);
|
||||
|
||||
@@ -82,11 +82,11 @@ describe("server_functions tests", () => {
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchResponseHeadersText.mock.calls.length).toBe(1);
|
||||
expect(fetchResponseHeadersText.mock.calls).toHaveLength(1);
|
||||
expect(sentData).toBe(responseData);
|
||||
});
|
||||
|
||||
test("Sends error data from response", async () => {
|
||||
it("Sends error data from response", async () => {
|
||||
const error = new Error("error data");
|
||||
fetchResponseHeadersText.mockImplementation(() => {
|
||||
throw error;
|
||||
@@ -99,32 +99,32 @@ describe("server_functions tests", () => {
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchResponseHeadersText.mock.calls.length).toBe(1);
|
||||
expect(fetchResponseHeadersText.mock.calls).toHaveLength(1);
|
||||
expect(sentData).toBe(error);
|
||||
});
|
||||
|
||||
test("Fetches with user agent by default", async () => {
|
||||
it("Fetches with user agent by default", async () => {
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][1]).toHaveProperty("headers");
|
||||
expect(fetchMock.mock.calls[0][1].headers).toHaveProperty("User-Agent");
|
||||
});
|
||||
|
||||
test("Fetches with specified headers", async () => {
|
||||
it("Fetches with specified headers", async () => {
|
||||
const headersParam = "sendheaders=header1:value1,header2:value2";
|
||||
const urlParam = "http://www.test.com/path?param1=value1";
|
||||
request.url = `/cors?${headersParam}&url=${urlParam}`;
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][1]).toHaveProperty("headers");
|
||||
expect(fetchMock.mock.calls[0][1].headers).toHaveProperty("header1", "value1");
|
||||
expect(fetchMock.mock.calls[0][1].headers).toHaveProperty("header2", "value2");
|
||||
});
|
||||
|
||||
test("Sends specified headers", async () => {
|
||||
it("Sends specified headers", async () => {
|
||||
fetchResponseHeadersGet.mockImplementation((input) => input.replace("header", "value"));
|
||||
|
||||
const expectedheaders = "expectedheaders=header1,header2";
|
||||
@@ -133,9 +133,9 @@ describe("server_functions tests", () => {
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][1]).toHaveProperty("headers");
|
||||
expect(corsResponse.set.mock.calls.length).toBe(3);
|
||||
expect(corsResponse.set.mock.calls).toHaveLength(3);
|
||||
expect(corsResponse.set.mock.calls[0][0]).toBe("Content-Type");
|
||||
expect(corsResponse.set.mock.calls[1][0]).toBe("header1");
|
||||
expect(corsResponse.set.mock.calls[1][1]).toBe("value1");
|
||||
|
Reference in New Issue
Block a user