Skip to content

Commit

Permalink
Fix unit tests / add more tests for index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Nov 23, 2020
1 parent 174008c commit d2200d5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/unit/framework.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("Middleware for UI5", () => {

const rewriteUrlBeforeSpy = jest.spyOn(framework, "rewriteUrlBefore");

const beforeMiddleware = framework.beforeMiddleware;
const beforeMiddleware = config.ui5._beforeMiddleware;

const req = {
url: "/foo"
Expand Down Expand Up @@ -71,7 +71,7 @@ describe("Middleware for UI5", () => {

const rewriteUrlSpy = jest.spyOn(framework, "rewriteUrl");

const middleware = framework.middleware;
const middleware = config.ui5._middleware;

const req = {
url: "/foo"
Expand Down Expand Up @@ -168,7 +168,8 @@ describe("UI5 Middleware / Proxy configuration", () => {
webapp: "webapp",
src: "src",
test: "test"
}
},
_middleware: expect.any(Function)
});
});

Expand Down
30 changes: 30 additions & 0 deletions test/unit/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ describe("Karma Plugin", () => {

await plugin["framework:ui5"][1](config1, logger1);

config1.ui5 = {
_middleware: jest.fn(),
_beforeMiddleware: jest.fn()
};

expect(frameworkInitStub).toHaveBeenCalledTimes(1);
expect(frameworkInitStub).toHaveBeenCalledWith({config: config1, logger: logger1});
expect(plugin["middleware:ui5--beforeMiddleware"][1](config1.ui5)).toBe(config1.ui5._beforeMiddleware);
expect(plugin["middleware:ui5--middleware"][1](config1.ui5)).toBe(config1.ui5._middleware);

const config2 = {};
const logger2 = {
Expand All @@ -53,7 +60,30 @@ describe("Karma Plugin", () => {

await plugin["framework:ui5"][1](config2, logger2);

config2.ui5 = {
_middleware: jest.fn(),
_beforeMiddleware: jest.fn()
};

expect(frameworkInitStub).toHaveBeenCalledTimes(2);
expect(frameworkInitStub).toHaveBeenCalledWith({config: config2, logger: logger2});
expect(plugin["middleware:ui5--beforeMiddleware"][1](config2.ui5)).toBe(config2.ui5._beforeMiddleware);
expect(plugin["middleware:ui5--middleware"][1](config2.ui5)).toBe(config2.ui5._middleware);
});
it("Should handle framework initialize error", async () => {
const Framework = require("../../lib/framework");
const plugin = require("../../");
jest.spyOn(Framework.prototype, "init").mockRejectedValue(new Error("Error from framework.init"));

const config = {};
const logger = {
create: jest.fn(() => {
return {
log: jest.fn()
};
})
};

await expect(plugin["framework:ui5"][1](config, logger)).rejects.toThrow("ss");
});
});

0 comments on commit d2200d5

Please sign in to comment.