当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript testing.it函数代码示例

本文整理汇总了TypeScript中angular2/testing.it函数的典型用法代码示例。如果您正苦于以下问题:TypeScript it函数的具体用法?TypeScript it怎么用?TypeScript it使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了it函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: describe

describe('Ng2Notify', () => {
	let notifyDirective: Ng2Notify;
	let notifyService: Ng2NotifyService = new Ng2NotifyService();
	let originalTimeout;

	beforeEach(() => {
		notifyDirective = new Ng2Notify(notifyService);

		originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
		jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;
	});

	afterEach(() => {
		jasmine.clock().uninstall();
		jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
	});

// TODO: Test subscribe
	it('should have a empty Array var "notifications"', () => {
		expect(notifyDirective.notifications).toEqual([]);
	});

	it('should have a null string "corner"', () => {
		expect(notifyDirective.corner).toBeNull(true);
	});

	it('notifyService should be a instance of Ng2NotifyService', () => {
		expect(notifyDirective.notifyService instanceof Ng2NotifyService).toBe(true);
	});

	it('if set a new notify, notifications.length should be 1', () => {
		notifyDirective.setNotify({
			'type': 'default',
			'message': 'Default notification.',
			'corner': 'right-top',
			'delay': 5000
		});
		expect(notifyDirective.notifications.length).toBe(1);
	});

	it('if set some notify\'s, notifications.length should be like notify\'s entered', () => {
		notifyDirective.setNotify({
			'type': 'default',
			'message': 'Default notification #1.',
			'corner': 'right-top',
			'delay': 5000
		});

		notifyDirective.setNotify({
			'type': 'default',
			'message': 'Default notification #2.',
			'corner': 'right-top',
			'delay': 5000
		});

		expect(notifyDirective.notifications.length).toBe(2);
	});

	it('when set a new notify, corner has new position', () => {
		notifyDirective.setNotify({
			'type': 'default',
			'message': 'Default notification #1.',
			'corner': 'right-top',
			'delay': 2000
		});

		expect(notifyDirective.corner).toBe('right-top');
	});

	it('delay seconds after set notify, should been has removed from array', (done) => {
		jasmine.clock().uninstall();
		jasmine.clock().install();

		notifyDirective.setNotify({
			'type': 'default',
			'message': 'Default notification #1.',
			'corner': 'right-top',
			'delay': 1000
		});

		expect(notifyDirective.notifications.length).toBe(1);
		expect(notifyDirective.notifications[0].notify).toBe(true);
		jasmine.clock().tick(1500);
		expect(notifyDirective.notifications.length).toBe(0);

		done();
	});
});
开发者ID:clamstew,项目名称:ng2-notify,代码行数:88,代码来源:ng2-notify.spec.ts

示例2: describe

	describe('Recommendations', () => {
		var rest: RestService;
		var mockBackend: MockBackend;
		var recommendation_fixtures: Array<Recommendation>;
		var category: Category;
		var questions: Array<Question>;

		beforeEach(() => {
			console.log('is this working? 0');
			recommendation_fixtures = new Array<Recommendation>();
			// Fill this with random shit
			for (let i = 0; i < recommendation_fixtures.length; i++) {
				recommendation_fixtures[i] = new Recommendation(
					faker.Lorem.words(),
					faker.Lorem.words(),
					faker.Lorem.words(),
					faker.Lorem.words(),
					faker.Lorem.words(),
					faker.Lorem.words(),
					faker.Lorem.words(),
					faker.Lorem.words(),
					faker.Lorem.words(),
					faker.Lorem.words(),
					faker.Lorem.words()
				)
			}
		});

		let before = (_rest, _mockBackend, cb) => {
			rest = _rest;
			mockBackend = _mockBackend;
			category = new Category(123, "test", "http://test.img");
			questions = new Array<Question>();
			for (let i = 0; i < 3; i ++) {
				questions.push(
					new Question(
						123,
						i,
						"faker.Lorem.words()",
						"faker.Lorem.words()",
						"faker.Lorem.words()",
						"faker.Lorem.words()",
						"faker.Lorem.words()",
						"faker.Lorem.words()"
					)
				);
			}

			ls.clear();
			
			rest.survey.like(category, questions[0]);
			rest.survey.dislike(category, questions[1]);
			rest.survey.maybe(category, questions[2]);

			mockBackend.connections.subscribe(c => {
				let match = c.request.url.match(/size=(\d+)/);
				console.log(match);
				if (match === null) throw new Error('Did not find parameter: size');
				let size = match[1];
				console.log('-----');
				match = c.request.url.match(/start=(\d+)/);
				console.log(match);
				if (match === null) throw new Error('Did not find parameter: start');
				let start = match[1];
				console.log('-----');

				console.log(`${BASE_API_URL}/api/explore/cruises?questions_liked=0&questions_disliked=1&questions_neutral=2&start=${start}&size=${size}`);
				console.log(c.request.url);
				// Handle all of our requests
				if (c.request.url === `${BASE_API_URL}/api/explore/cruises?questions_liked=123&questions_disliked=234&questions_neutral=345&start=${start}&size=${size}` && c.request.method === 0) {
					send200({
						"results": recommendation_fixtures.slice(start, size)
					}, c);
					return;
				}
			});
			cb();
		};

		it('querySet()', beforeHack(before, () => {
			// This gets tested through our other methods
		}));

		it('initializeRecommendations()', beforeHack(before, () => {
			console.log('is this working? 3');
			// We expect to get only the first 10 paginated recommendations
			rest.recommendations.initializeRecommendations((err, recommendations: Array<Recommendation>) => {
				console.log('//////');
				console.log(recommendations.length);
				console.log('//////');
				expect(recommendations.length).toBe(11);
				
			});
		}));

		it('paginate()', beforeHack(before, () => {

		}));

		it('get()', beforeHack(before, () => {
//.........这里部分代码省略.........
开发者ID:saikonda,项目名称:cruise-pas-public,代码行数:101,代码来源:rest.service.spec.ts

示例3: describe

describe('AppComponent with new', function () {
    it('should instantiate component', () => {
      expect(new AppComponent()).not.toBeNull('Whoopie!');
    });
});
开发者ID:aferlazzo,项目名称:ng2_routing,代码行数:5,代码来源:app.component.spec.ts

示例4: describe

describe('Videogular Player', () => {
    let overlayPlay: VgOverlayPlay;
    let ref:ElementRef;
    let api:VgAPI;

    beforeEach(() => {
        ref = {
            nativeElement: {
                getAttribute: (name) => {
                    return name;
                }
            }
        };

        api = new VgAPI();
        overlayPlay = new VgOverlayPlay(ref, api);
    });

    it('Should get media by id on init', () => {
        spyOn(overlayPlay.elem, 'getAttribute').and.callThrough();
        spyOn(api, 'getMediaById').and.callFake(() => { });

        overlayPlay.ngOnInit();

        expect(overlayPlay.elem.getAttribute).toHaveBeenCalledWith('vg-for');
        expect(api.getMediaById).toHaveBeenCalledWith('vg-for');
    });

    describe('onClick', () => {
        beforeEach(() => {
            overlayPlay.target = {
                play: () => { },
                pause: () => { }
            }
        });

        it('current state play should set target to pause', () => {
            spyOn(overlayPlay, 'getState').and.callFake(() => { return 'play' });
            spyOn(overlayPlay.target, 'pause');

            overlayPlay.onClick();

            expect(overlayPlay.getState).toHaveBeenCalled();
            expect(overlayPlay.target.pause).toHaveBeenCalled();
        });

        it('current state pause should set target to play', () => {
            spyOn(overlayPlay, 'getState').and.callFake(() => { return 'pause' });
            spyOn(overlayPlay.target, 'play');

            overlayPlay.onClick();

            expect(overlayPlay.getState).toHaveBeenCalled();
            expect(overlayPlay.target.play).toHaveBeenCalled();
        });
    });

    describe('getState', () => {
        beforeEach(() => {
            overlayPlay.target = {
                state: null
            }
        });

        it('if only one state returns that state', () => {
            overlayPlay.target.state = 'pause';

            expect(overlayPlay.getState()).toEqual('pause');
        });

        it('if more than one target should return pause if all of them are pause', () => {
            overlayPlay.target.state = ['pause','pause','pause','pause'];

            expect(overlayPlay.getState()).toEqual('pause');
        });

        it('if more than one target should return play if any of them is play', () => {
            overlayPlay.target.state = ['pause','play','pause','pause'];

            expect(overlayPlay.getState()).toEqual('play');
        });
    });
});
开发者ID:aschuettler,项目名称:videogular2,代码行数:83,代码来源:vg-overlay-play.spec.ts

示例5: describe

  describe('Angulartics2GoogleAnalytics', () => {
    var ga: any;
    var _gaq: Array<any>;
    var fixture: ComponentFixture;

    beforeEachProviders(() => [
      TEST_ROUTER_PROVIDERS,
      Angulartics2,
      Angulartics2GoogleAnalytics
    ]);

    beforeEach(function() {
      window.ga = ga = jasmine.createSpy('ga');
      window._gaq = _gaq = [];
    });

    it('should track initial page',
      inject([TestComponentBuilder, Router, Angulartics2, Angulartics2GoogleAnalytics],
        (tcb: TestComponentBuilder, router: Router, angulartics2: Angulartics2, angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => router.config([new Route({ path: '/', component: HelloCmp })]))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                setTimeout(() => {
                  expect(_gaq).toContain(['_trackPageview', '']);
                  expect(ga).toHaveBeenCalledWith('send', 'pageview', '');
                  resolve();
                });
              });
            });
        }));

    it('should track pages',
      inject([TestComponentBuilder, Router, Angulartics2, Angulartics2GoogleAnalytics],
        (tcb: TestComponentBuilder, router: Router, angulartics2: Angulartics2, angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => router.config([new Route({ path: '/abc', component: HelloCmp })]))
            .then((_) => router.navigateByUrl('/abc'))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                setTimeout(() => {
                  expect(ga).toHaveBeenCalledWith('send', 'pageview', '/abc');
                  resolve();
                });
              });
            });
        }));

    it('should track events',
      inject([TestComponentBuilder, Angulartics2, Angulartics2GoogleAnalytics],
        (tcb: TestComponentBuilder, angulartics2: Angulartics2, angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => angulartics2.eventTrack.next({ action: 'do', properties: { category: 'cat' } }))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
              //   setTimeout(() => {
                  expect(ga).toHaveBeenCalledWith('send', 'event', { eventCategory: 'cat', eventAction: 'do', eventLabel: undefined, eventValue: undefined, nonInteraction: undefined, page: '/context.html', userId: null });
                  resolve();
              //   });
              });
            });
        }));

    it('should track exceptions',
      inject([TestComponentBuilder, Angulartics2, Angulartics2GoogleAnalytics],
        ((tcb: TestComponentBuilder, angulartics2: Angulartics2, angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => angulartics2.exceptionTrack.next({ appId: 'app', appName: 'Test App', appVersion: '0.1' }))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
              //   setTimeout(() => {
                  expect(ga).toHaveBeenCalledWith('send', 'exception', { appId: 'app', appName: 'Test App', appVersion: '0.1', exFatal: true, exDescription: undefined });
                  resolve();
              //   });
              });
            });
        })));

    it('should set username',
      inject([TestComponentBuilder, Angulartics2, Angulartics2GoogleAnalytics],
        (tcb: TestComponentBuilder, angulartics2: Angulartics2, angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => angulartics2.setUsername.next('testuser'))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                setTimeout(() => {
                  expect(angulartics2.settings.ga.userId).toBe('testuser');
                  resolve();
                });
              });
//.........这里部分代码省略.........
开发者ID:JulioC,项目名称:angulartics2,代码行数:101,代码来源:angulartics2-google-analytics.spec.ts

示例6: describe

describe('Mockbase', () => {

  beforeEachProviders(() => [MockbaseService]);

  it('default farms list has 2 items', inject([MockbaseService], (service: MockbaseService) => {
    return o2ap(service.getFarms()).then((arr) => {
      expect(arr[1].code).toEqual("farm2");
      expect(arr.length).toEqual(2);
    });
  }));

  it('add farm works', inject([MockbaseService], (service: MockbaseService) => {
    return service.addFarm({ code: "test9", some: 13 }).then(() => {
      return o2ap(service.getFarms()).then((arr) => {
        expect(arr.length).toEqual(3);
        expect(arr[2].code).toEqual("test9");
      });
    });
  }));

  it('default plant list has 4 items', inject([MockbaseService], (service: MockbaseService) => {
    return o2ap(service.getPlants()).then((arr) => {
      expect(arr[3].code).toEqual("plant5");
      expect(arr.length).toEqual(4);
    });
  }));

  it('add plant works', inject([MockbaseService], (service: MockbaseService) => {
    return service.addPlant({ code: "test9", some: 13 }).then(() => {
      return o2ap(service.getPlants()).then((arr) => {
        expect(arr.length).toEqual(5);
        expect(arr[4].code).toEqual("test9");
      });
    });
  }));

  //3 days x 4 plants x 2 farms = 24 entries
  it('default harvest log has 24 entries', inject([MockbaseService], (service: MockbaseService) => {
    return o2ap(service.getHarvestLog("2016-05-01")).then((arr) => {
      expect(arr.length).toEqual(8);
      expect(arr[5].day).toEqual("2016-05-01");
      expect(arr[5].farm).toEqual("farm2");
      expect(arr[5].plant).toEqual("plant2");
      checkIsQuantity(arr[5].quantity);
    });
  }));

  it('default log for unknown day is empty', inject([MockbaseService], (service: MockbaseService) => {
    return o2ap(service.getHarvestLog("2016-06-01")).then((arr) => {
      expect(arr.length).toEqual(0);
    });
  }));

  it('add harvest works for known day', inject([MockbaseService], (service: MockbaseService) => {
    let d = "2016-05-01";
    let harvest = { day: d, farm: "farm1", plant: "plant1", quantity: 13 };
    return service.addHarvest(harvest).then(() => {
      return o2ap(service.getHarvestLog(d)).then((arr) => {
        expect(arr.length).toEqual(9);
        expect(arr[8]).toEqual(harvest);
      });
    });
  }));

  it('add harvest works for unknown day', inject([MockbaseService], (service: MockbaseService) => {
    let d = "2016-06-01";
    let harvest = { day: d, farm: "farm1", plant: "plant1", quantity: 13 };
    return service.addHarvest(harvest).then(() => {
      return o2ap(service.getHarvestLog(d)).then((arr) => {
        expect(arr.length).toEqual(1);
        expect(arr[0]).toEqual(harvest);
      });
    });
  }));

  it('autheticate test/test only', inject([MockbaseService], (service: MockbaseService) => {
    return Promise.all([
      service.authenticate("test", "test").then((auth) => {
        expect(auth).toEqual({ uid: "123", email: "test", token: "xyz" });
      }),
      service.authenticate("x", "test").catch((reason) => {
        expect(reason).toContain("INVALID EMAIL");
      }),
      service.authenticate("test", "x").catch((reason) => {
        expect(reason).toContain("INVALID PASSWORD");
      }),
    ]);
  }));

  it('harvest logs for known range', inject([MockbaseService], (service: MockbaseService) => {
    return o2ap2(service.getHarvestLogs("2016-04-30", "2016-05-07")).then((days) => {
      expect(days.keys.length).toEqual(3);
      
      expect(days.keys[0]).toEqual("2016-05-01");
      checkObj(days.vals[0], 8, 6)
      expect(days.keys[1]).toEqual("2016-05-02");
      checkObj(days.vals[1], 8, 2)
      expect(days.keys[2]).toEqual("2016-05-03");
      checkObj(days.vals[2], 8, 5)
      expect(days.keys[4]).toEqual(undefined);
//.........这里部分代码省略.........
开发者ID:Tattvum,项目名称:nallakeerai,代码行数:101,代码来源:mockbase.service.spec.ts

示例7: describe

describe('A simple test', () => {
  it('should work', () => {
    expect(null).toBeDefined();
  });
});
开发者ID:Bernardao,项目名称:fem-ng2-examples,代码行数:5,代码来源:my.component.spec.ts

示例8: describe

  describe('Angulartics2Kissmetrics', () => {
    var _kmq: Array<any>;
    var fixture: ComponentFixture;

    beforeEachProviders(() => [
      TEST_ROUTER_PROVIDERS,
      Angulartics2,
      Angulartics2Kissmetrics
    ]);

    beforeEach(function() {
      window._kmq = _kmq = [];
    });

    it('should track initial page',
      inject([TestComponentBuilder, Router, Angulartics2, Angulartics2Kissmetrics],
        (tcb: TestComponentBuilder, router: Router, angulartics2: Angulartics2, angulartics2Kissmetrics: Angulartics2Kissmetrics) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => router.config([new Route({ path: '/', component: HelloCmp })]))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                setTimeout(() => {
                  expect(_kmq).toContain(['record', 'Pageview', { 'Page': '' }]);
                  resolve();
                });
              });
            });
        }));

    it('should track pages',
      inject([TestComponentBuilder, Router, Angulartics2, Angulartics2Kissmetrics],
        (tcb: TestComponentBuilder, router: Router, angulartics2: Angulartics2, angulartics2Kissmetrics: Angulartics2Kissmetrics) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => router.config([new Route({ path: '/abc', component: HelloCmp })]))
            .then((_) => router.navigateByUrl('/abc'))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                setTimeout(() => {
                  expect(_kmq).toContain(['record', 'Pageview', { 'Page': '/abc' }]);
                  resolve();
                });
              });
            });
        }));

    it('should track events',
      inject([TestComponentBuilder, Angulartics2, Angulartics2Kissmetrics],
        (tcb: TestComponentBuilder, angulartics2: Angulartics2, angulartics2Kissmetrics: Angulartics2Kissmetrics) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => angulartics2.eventTrack.next({ action: 'do', properties: { category: 'cat' } }))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                // setTimeout(() => {
                  expect(_kmq).toContain(['record', 'do', { category: 'cat' }]);
                  resolve();
                // });
              });
            });
        }));

    it('should set username',
      inject([TestComponentBuilder, Angulartics2, Angulartics2Kissmetrics],
        ((tcb: TestComponentBuilder, angulartics2: Angulartics2, angulartics2Kissmetrics: Angulartics2Kissmetrics) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => angulartics2.setUsername.next('testUser'))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                // setTimeout(() => {
                  expect(_kmq).toContain(['identify', 'testUser']);
                  resolve();
                // });
              });
            });
        })));

    it('should set user properties',
      inject([TestComponentBuilder, Angulartics2, Angulartics2Kissmetrics],
        ((tcb: TestComponentBuilder, angulartics2: Angulartics2, angulartics2Kissmetrics: Angulartics2Kissmetrics) => {
          compile(tcb)
            .then((rtc) => fixture = rtc)
            .then((_) => angulartics2.setUserProperties.next({ userId: '1', firstName: 'John', lastName: 'Doe' }))
            .then((_) => {
              fixture.detectChanges();
              return new Promise((resolve) => {
                setTimeout(() => {
                  expect(_kmq).toContain(['set', { userId: '1', firstName: 'John', lastName: 'Doe' }]);
                  resolve();
                });
              });
            });
        })));

//.........这里部分代码省略.........
开发者ID:JulioC,项目名称:angulartics2,代码行数:101,代码来源:angulartics2-kissmetrics.spec.ts

示例9: describe

describe('GameLauncherServiceTests', () => {
  beforeEachProviders(() => [BaseRequestOptions,
    MockBackend,
    provide(Http, {
      useFactory: (backend, defaultOptions) => {
        return new Http(backend, defaultOptions);
      },
      deps: [MockBackend, BaseRequestOptions]
    }),
    GlobalService,
    GameLauncherService
  ]);

  it('should have http', inject([GameLauncherService], (instance) => {
    expect(!!instance.http).toEqual(true);
  }));

  it('loadGame_givenCommand_shouldCallApiStartGame',
    inject([GameLauncherService, MockBackend], (instance, mockBackend) => {
      // Arrange
      mockBackend.connections.subscribe(
        (connection: MockConnection) => {
          connection.mockRespond(new Response(
            new ResponseOptions({
              status: 200
            })));
        });

      // Act
      instance.loadGame('command').subscribe(
        (data) => {
          // Assert
          expect(data.status).toBe(200);
        },
        (error) => {
          fail(error);
        }
      );
    }));

  it('isGameStarted_givenResponsiveHTTP_shouldCallApiIsGameStarted',
    inject([GameLauncherService, MockBackend], (instance, mockBackend) => {
      // Arrange
      mockBackend.connections.subscribe(
        (connection: MockConnection) => {
          connection.mockRespond(new Response(
            new ResponseOptions({
              body: JSON.stringify(true)
            })));
        });

      // Act
      instance.isGameStarted().subscribe(
        (data) => {
          // Assert
          expect(data).toBeTruthy();
        },
        (error) => {
          fail(error);
        }
      );
    }));
});
开发者ID:dragica,项目名称:OPEN_Launcher,代码行数:63,代码来源:GameLauncherService.spec.ts


注:本文中的angular2/testing.it函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。