-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests for clientUnarydEcorator
- Loading branch information
1 parent
837950a
commit d1a9a3c
Showing
2 changed files
with
39 additions
and
6 deletions.
There are no files selected for viewing
42 changes: 36 additions & 6 deletions
42
__tests__/callFactories/callDecorators/clientUnaryDecorator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,46 @@ | ||
const object = {}; | ||
const clientUnaryDecorator = require("../../../lib/callFactories/callDecorators/clientUnaryDecorator"); | ||
|
||
const customCall = {}; | ||
|
||
const mockOn = jest.fn(); | ||
const mockCallback = jest.fn(); | ||
const originalCall = { | ||
hello: "hello" | ||
hello: "hello", | ||
request: "request", | ||
metadata: "metadata", | ||
on: mockOn | ||
}; | ||
const clientUnaryDecorator = require("../../../lib/callFactories/callDecorators/clientUnaryDecorator"); | ||
|
||
clientUnaryDecorator(customCall, originalCall); | ||
|
||
describe("tests for client unary decorator", () => { | ||
describe("basic Tests for method assignment", () => { | ||
it("should have an on", () => { | ||
expect(customCall.hasOwnProperty("on")).toBeTruthy(); | ||
}); | ||
|
||
it("should assign the body property to be call's request", () => { | ||
expect(customCall.body).toBe(originalCall.request); | ||
}); | ||
|
||
it("should assign the head to be the metadata", () => { | ||
expect(customCall.head).toBe(originalCall.metadata); | ||
}); | ||
}); | ||
|
||
describe("tests for on method", () => { | ||
beforeEach(() => { | ||
clientUnaryDecorator(object, () => {}); | ||
mockOn.mockClear(); | ||
mockCallback.mockClear(); | ||
}); | ||
it("should have an on", () => { | ||
expect(object.hasOwnProperty("on")).toBeTruthy(); | ||
it("on should accept a data string and callback", () => { | ||
customCall.on("data", mockCallback); | ||
expect(mockCallback.mock.calls.length).toBe(1); | ||
}); | ||
|
||
it("should work without a string and just a callback", () => { | ||
customCall.on(mockCallback); | ||
expect(mockCallback.mock.calls.length).toBe(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters