本文整理汇总了TypeScript中angular.mock类的典型用法代码示例。如果您正苦于以下问题:TypeScript mock类的具体用法?TypeScript mock怎么用?TypeScript mock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了mock类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: beforeEach
beforeEach(() => {
mock.module(HELP_FIELD_COMPONENT, ($provide: IProvideService) => {
$provide.constant('helpContents', { 'aws.serverGroup.stack': 'expected stack help' });
});
});
开发者ID:emjburns,项目名称:deck,代码行数:5,代码来源:helpField.component.spec.ts
示例2: describe
describe("PageEditorService", () => {
let service: PageEditorService, dataService: DataService;
beforeEach(() => {
angular.mock.module(PAGE_EDITOR_MODULE);
angular.mock.module(DATA_MODULE);
});
beforeEach(angular.mock.inject($injector => {
service = $injector.get("PageEditorService");
dataService = $injector.get("DataService");
spyOn(dataService, "getData");
}));
it("should get data when getPages is called for editor page", () => {
service.getPages();
expect(dataService.getData).toHaveBeenCalledWith({
webservice: "api/pages?includeHtml=N",
type: "GET"
});
});
it("should get updatable pages when getUpdatablePages is called", () => {
service.getUpdatablePages();
expect(dataService.getData).toHaveBeenCalledWith({
webservice: "api/pages?isUpdatable=true",
type: "GET"
});
});
it("should post all updatable pages when postAllPagesFromRepo is called", () => {
service.postAllPagesFromRepo();
expect(dataService.getData).toHaveBeenCalledWith({
webservice: "api/pages",
type: "POST"
});
});
it("should post single page when postPageFromRepo is called", () => {
service.postPageFromRepo("12steps");
expect(dataService.getData).toHaveBeenCalledWith({
webservice: "api/pages/12steps",
type: "POST"
});
});
it("should get data when getMeetings is called for editor page", () => {
service.getPage("12steps", 2);
expect(dataService.getData).toHaveBeenCalledWith({
webservice: "api/pages?pageName=12steps&revision=2",
type: "GET"
});
});
it("should post single page when postPage is called", () => {
service.postPage("read-andallo", 3, {
PageTitle: "...And All Other Mind Altering Substances",
PageContent: "<div>new content</div>",
Status: "ACTIVE",
ContentType: "R",
ImageFilename: "PAMPHLETS_All_Other"
});
expect(dataService.getData).toHaveBeenCalledWith({
webservice: "api/pages/read-andallo/3",
type: "POST",
payload: {
PageTitle: "...And All Other Mind Altering Substances",
PageContent: "<div>new content</div>",
Status: "ACTIVE",
ContentType: "R",
ImageFilename: "PAMPHLETS_All_Other"
}
});
});
});
开发者ID:disco-funk,项目名称:ca-london-angular,代码行数:82,代码来源:page-editor.service.spec.ts
示例3: describe
describe('Controller: LoadBalancerDetailsCtrl', function() {
let controller: AwsLoadBalancerDetailsController;
let $scope;
let $state;
const loadBalancer = {
name: 'foo',
region: 'us-west-1',
account: 'test',
accountId: 'test',
vpcId: '1',
};
beforeEach(mock.module(AWS_LOAD_BALANCER_DETAILS_CTRL));
beforeEach(
mock.inject(($controller: IControllerService, $rootScope: IRootScopeService, _$state_: StateService) => {
$scope = $rootScope.$new();
$state = _$state_;
const app = ApplicationModelBuilder.createApplicationForTests('app', { key: 'loadBalancers', lazy: true });
app.loadBalancers.data.push(loadBalancer);
controller = $controller(AwsLoadBalancerDetailsController, {
$scope,
loadBalancer,
app,
$state,
});
}),
);
it('should have an instantiated controller', function() {
expect(controller).toBeDefined();
});
describe('Get the first subnets purpose', function() {
it('should return empty string if there are no subnets ', function() {
const subnetDetails: ISubnet[] = [];
const result = controller.getFirstSubnetPurpose(subnetDetails);
expect(result).toEqual('');
});
it('should return empty string if no subnetDetail is submitted', function() {
const result = controller.getFirstSubnetPurpose();
expect(result).toEqual('');
});
it('should return empty string if undefined subnetDetail is submitted', function() {
const result = controller.getFirstSubnetPurpose(undefined);
expect(result).toEqual('');
});
it('should return the first purpose of subnetDetail if there is only one', function() {
const subnetDetails = [{ purpose: 'internal(vpc0)' }] as ISubnet[];
const result = controller.getFirstSubnetPurpose(subnetDetails);
expect(result).toEqual('internal(vpc0)');
});
it('should return the first purpose of subnetDetail if there are multiple', function() {
const subnetDetails = [{ purpose: 'internal(vpc0)' }, { purpose: 'internal(vpc1)' }] as ISubnet[];
const result = controller.getFirstSubnetPurpose(subnetDetails);
expect(result).toEqual('internal(vpc0)');
});
});
});
开发者ID:emjburns,项目名称:deck,代码行数:63,代码来源:loadBalancerDetails.controller.spec.ts
示例4: beforeEach
beforeEach(() => {
angular.mock.module('officeuifabric.core');
angular.mock.module('officeuifabric.components.callout');
});
开发者ID:sjclemmy,项目名称:ng-officeuifabric,代码行数:4,代码来源:calloutDirective.spec.ts
示例5: beforeEach
beforeEach(() => {
angular.mock.module(PAGE_EDITOR_MODULE);
angular.mock.module(DATA_MODULE);
});
开发者ID:disco-funk,项目名称:ca-london-angular,代码行数:4,代码来源:page-editor.service.spec.ts
示例6: beforeEach
beforeEach(() => angular.mock.module(CORE_MODULE));
开发者ID:disco-funk,项目名称:ca-london-angular,代码行数:1,代码来源:page-router.controller.spec.ts
示例7: beforeEach
beforeEach(() => {
angular.mock.inject(() => {
dialogValidation = new DialogValidation();
});
});
开发者ID:himdel,项目名称:ui-components,代码行数:6,代码来源:dialogValidationService.spec.ts
示例8: beforeEach
beforeEach(() => angular.mock.module(MEETINGS_MODULE));
开发者ID:disco-funk,项目名称:ca-london-angular,代码行数:1,代码来源:meeting-district.controller.spec.ts
示例9: describe
describe("PageRouterCtrl", () => {
let ctrl: PageRouterCtrl, pageRouterService: PageRouterService, caLondonAppConfig: ICALondonAppConfig;
let $controller: IControllerService, $rootScope: IRootScopeService, $scope: IScope, $q: IQService,
$templateCache: ITemplateCacheService, $timeout: ITimeoutService, $httpBackend: IHttpBackendService,
$window: IWindowService, $routeParams;
beforeEach(() => angular.mock.module(CORE_MODULE));
beforeEach(angular.mock.inject($injector => {
$controller = $injector.get("$controller");
$rootScope = $injector.get("$rootScope");
$window = $injector.get("$window");
$q = $injector.get("$q");
$routeParams = $injector.get("$routeParams");
$templateCache = $injector.get("$templateCache");
$timeout = $injector.get("$timeout");
$httpBackend = $injector.get("$httpBackend");
$scope = $rootScope.$new(true);
caLondonAppConfig = $injector.get("caLondonAppConfig");
pageRouterService = $injector.get("PageRouterService");
caLondonAppConfig.API_URL = "https://myurl.com/";
$routeParams.pageName = "testpage";
$httpBackend.whenGET("https://myurl.com/api/pages?contentType")
.respond([]);
}));
function initController(): void {
ctrl = $controller("PageRouterCtrl", {
$scope: $scope
});
}
describe("initialising controller", () => {
it("should exist", () => {
initController();
expect(ctrl).toBeDefined();
});
it("should initialise and load loading page when template cache is not ready", () => {
pageRouterService.templateLoadingState = TemplateState.NotReady;
spyOn(pageRouterService, "getPageTitle").and.returnValue("Test Page");
spyOn($templateCache, "get").and.callFake(page => {
if (page === "page/testpage.html") {
return "<div>some template</div>";
} else if (page === "page/disclaimmain.html") {
return "<div>disclaimer</div>";
}
});
initController();
expect(ctrl.pageData).toEqual([
{PageContent: `<div id="loader"></div>`, PageTitle: "CA London"}
]);
expect(ctrl.pageName).toEqual("testpage");
expect($window.document.title).toEqual("Cocaine Anonymous London");
pageRouterService.templateLoadingState = TemplateState.Ready;
$timeout.flush();
expect(ctrl.pageData).toEqual([
{PageContent: "<div>some template</div>"},
{PageContent: "<div>disclaimer</div>"}
]);
expect(ctrl.pageName).toEqual("testpage");
expect($window.document.title).toEqual("Test Page | Cocaine Anonymous London");
});
it("should load page if cache is not populated", () => {
pageRouterService.templateLoadingState = TemplateState.Ready;
spyOn(pageRouterService, "getPageTitle").and.returnValue("Test Page");
spyOn($templateCache, "get").and.callFake(page => {
if (page === "page/testpage.html") {
return "<div>some template</div>";
} else if (page === "page/disclaimmain.html") {
return "<div>disclaimer</div>";
}
});
initController();
expect(ctrl.pageData).toEqual([
{PageContent: "<div>some template</div>"},
{PageContent: "<div>disclaimer</div>"}
]);
expect(ctrl.pageName).toEqual("testpage");
expect($window.document.title).toEqual("Test Page | Cocaine Anonymous London");
});
it("should load error page if cache has errored", () => {
pageRouterService.templateLoadingState = TemplateState.Errored;
spyOn(pageRouterService, "getPageTitle").and.returnValue("Error");
spyOn($templateCache, "get").and.callFake(page => {
if (page === "page/error.html") {
return "<div>error template</div>";
}
//.........这里部分代码省略.........
开发者ID:disco-funk,项目名称:ca-london-angular,代码行数:101,代码来源:page-router.controller.spec.ts
示例10: describe
describe("MeetingDistrictCtrl", () => {
let ctrl: MeetingDistrictCtrl, meetingService: MeetingService;
let $controller: IControllerService, $rootScope: IRootScopeService, $scope: IScope, $q: IQService;
let fakeDistrictForm;
beforeEach(() => angular.mock.module(MEETINGS_MODULE));
beforeEach(angular.mock.inject($injector => {
$controller = $injector.get("$controller");
$rootScope = $injector.get("$rootScope");
$q = $injector.get("$q");
meetingService = $injector.get("MeetingService");
$scope = $rootScope.$new(true);
spyOn(meetingService, "getDistricts").and.callFake(() => {
const deferred: IDeferred<Array<IDistrict>> = $q.defer();
deferred.resolve(TestDistricts);
return deferred.promise;
});
fakeDistrictForm = {$setPristine: () => {}};
ctrl = $controller("MeetingDistrictCtrl", {
$scope: $scope
});
}));
it("should initialise", () => {
expect(ctrl).toBeDefined();
expect(ctrl.districts).toEqual([]);
expect(ctrl.areaEditor).toEqual({
areaStatus: ctrl.NOT_STARTED,
editingArea: undefined,
newAreaDescription: undefined
});
expect(ctrl.districtEditor.districtStatus).toEqual(ctrl.NOT_STARTED);
expect(ctrl.districtEditor.newDistrictDescription).toBeUndefined();
expect(ctrl.districtEditor.editingDistrict).toBeUndefined();
expect(ctrl.isLoading).toEqual(true);
$scope.$digest();
expect(meetingService.getDistricts).toHaveBeenCalled();
expect(ctrl.districts).toEqual(TestDistricts);
expect(ctrl.areas).toEqual([
{Area: "CENTRAL", AreaDescription: "Central"},
{Area: "LONDON", AreaDescription: "London"},
{Area: "UK", AreaDescription: "UK"}
]);
expect(ctrl.isLoading).toEqual(false);
});
describe("#calculateId", () => {
it("should calculate correct Id", () => {
expect(ctrl.calculateId("Some area name")).toEqual("SOMEAREANA");
});
});
describe("Area Form", () => {
describe("#editArea", () => {
it("should edit existing area", () => {
ctrl.editArea({Area: "LONDON", AreaDescription: "London"});
expect(ctrl.areaEditor).toEqual({
areaStatus: ctrl.STARTED,
editingArea: {Area: "LONDON", AreaDescription: "London"},
newAreaDescription: "London"
});
});
it("should add new area", () => {
ctrl.editArea();
expect(ctrl.areaEditor).toEqual({
areaStatus: ctrl.STARTED,
editingArea: undefined,
newAreaDescription: undefined
});
});
});
describe("#cancelAddArea", () => {
it("should cancel", () => {
ctrl.areaEditor = {
areaStatus: ctrl.SUCCESS,
editingArea: {Area: "LONDON", AreaDescription: "London"},
newAreaDescription: "something"
};
ctrl.cancelAddArea();
expect(ctrl.areaEditor).toEqual({
areaStatus: ctrl.NOT_STARTED,
editingArea: undefined,
newAreaDescription: undefined
});
});
});
//.........这里部分代码省略.........
开发者ID:disco-funk,项目名称:ca-london-angular,代码行数:101,代码来源:meeting-district.controller.spec.ts
注:本文中的angular.mock类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论