本文整理匯總了TypeScript中models/shared/version_updater.VersionUpdater類的典型用法代碼示例。如果您正苦於以下問題:TypeScript VersionUpdater類的具體用法?TypeScript VersionUpdater怎麽用?TypeScript VersionUpdater使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了VersionUpdater類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Date
jasmine.Ajax.withMock(() => {
jasmine.Ajax.stubRequest("/go/api/version_infos/stale", undefined, "GET").andReturn({
responseText: JSON.stringify({}),
status: 200
});
jasmine.Ajax.stubRequest("/go/api/version_infos/latest_version", undefined, "GET").andReturn({
responseText: JSON.stringify({}),
status: 200
});
const thirtyOneMinutesBack = new Date(Date.now() - 31 * 60 * 1000);
localStorage.setItem("versionCheckInfo", JSON.stringify({last_updated_at: thirtyOneMinutesBack}));
VersionUpdater.update();
const request = jasmine.Ajax.requests.at(0);
expect(request.method).toBe("GET");
expect(request.url).toBe("/go/api/version_infos/stale");
expect(request.requestHeaders["Content-Type"]).toContain("application/json");
expect(request.requestHeaders.Accept).toContain("application/vnd.go.cd.v1+json");
expect(JSON.parse(localStorage.getItem("system_notifications") as string)).toBeNull();
});
示例2: spyOn
jasmine.Ajax.withMock(() => {
jasmine.Ajax.stubRequest("/go/api/version_infos/stale", undefined, "GET").andReturn({
responseText: JSON.stringify({update_server_url: "update.server.url"}),
responseHeaders: {
"Content-Type": `application/vnd.go.cd.v1+json`,
},
status: 200
});
jasmine.Ajax.stubRequest("update.server.url", undefined, "GET").andReturn({
responseText: JSON.stringify({foo: "bar"}),
responseHeaders: {
"Content-Type": "application/json"
},
status: 200
});
jasmine.Ajax.stubRequest("/go/api/version_infos/go_server", undefined, "PATCH").andReturn({
responseText: JSON.stringify({}),
responseHeaders: {
"Content-Type": `application/vnd.go.cd.v1+json`
},
status: 200
});
const myDate = jasmine.createSpyObj("Date", ["getTime"]);
// @ts-ignore
spyOn(window, "Date").and.returnValue(myDate);
myDate.getTime.and.callFake(() => 123);
VersionUpdater.update();
const request = jasmine.Ajax.requests.at(2);
expect(request.method).toBe("PATCH");
expect(request.url).toBe("/go/api/version_infos/go_server");
expect(JSON.parse(request.params)).toEqual({foo: "bar"});
expect(request.requestHeaders["Content-Type"]).toContain("application/json");
expect(request.requestHeaders.Accept).toContain("application/vnd.go.cd.v1+json");
expect(localStorage.getItem("versionCheckInfo")).toEqual("{\"last_updated_at\":123}");
});
示例3: expect
jasmine.Ajax.withMock(() => {
jasmine.Ajax.stubRequest("/go/api/version_infos/stale", undefined, "GET").andReturn({
responseText: JSON.stringify({update_server_url: "update.server.url"}),
status: 200
});
jasmine.Ajax.stubRequest("update.server.url", undefined, "GET").andReturn({
responseText: JSON.stringify({}),
status: 200
});
VersionUpdater.update();
const request = jasmine.Ajax.requests.at(1);
expect(request.method).toBe("GET");
expect(request.url).toBe("update.server.url");
expect(request.requestHeaders.Accept).toContain("application/vnd.update.go.cd.v1+json");
});