-
-
Notifications
You must be signed in to change notification settings - Fork 286
/
CalendarCtrl.spec.ts
41 lines (34 loc) · 1.28 KB
/
CalendarCtrl.spec.ts
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
import {TestContext} from "@tsed/testing";
import {expect} from "chai";
import * as Sinon from "sinon";
import {CalendarsService} from "../../services/calendars/CalendarsService";
import {MemoryStorage} from "../../services/storage/MemoryStorage";
import {CalendarCtrl} from "./CalendarCtrl";
describe("CalendarsCtrl", () => {
describe("without IOC", () => {
it("should do something", () => {
// GIVEN
const calendarsCtrl = new CalendarCtrl(new CalendarsService(new MemoryStorage()));
expect(calendarsCtrl).to.be.an.instanceof(CalendarCtrl);
});
});
describe("with mocking dependencies", () => {
before(() => TestContext.create());
after(() => TestContext.reset());
it("should return the expected result", () => {
// GIVEN
const calendarsService = {
find: Sinon.stub().returns(Promise.resolve({id: "1"}))
};
const calendarController = TestContext.invoke(CalendarCtrl, [
{provide: CalendarsService, use: calendarsService}
]);
// WHEN
const result = calendarController.get("1");
// THEN
result.should.eventually.deep.equal({id: "1"});
calendarsService.find.should.be.calledWithExactly("1");
expect(calendarController.calendarsService).to.equal(calendarsService);
});
});
});