How to use the angular2/testing.it function in angular2

To help you get started, we’ve selected a few angular2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SSWConsulting / enterprise-musicstore-ui-angular2 / src / SSW.MusicStore.Web / src / components / app / app.component.spec.ts View on Github external
provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent}),
    MockBackend,
    BaseRequestOptions,
    provide(Http, {
      useFactory: (backend, options) => new Http(backend, options), 
      deps: [MockBackend, BaseRequestOptions]})
  ]);

    beforeEach(inject([Router, Location, GenreService, AppComponent], (r, l, g, a) => {
        router = r;
        location = l;
        genreService = g;
        appComponent = a;
    }));

    it('Should be able to navigate to Home', done => {
        router.navigate(['Orders']).then(() => {
            expect(location.path()).toBe('/orders');
            done();
        }).catch(e => done.fail(e));
    });
    
    // it('should greet', () => {
    //  //   expect(appComponent.title).toBe('SSW Angular 2 Music Store');
    // })

})
github ludohenin / ng2-wp-blog / src / app / app.component.spec.ts View on Github external
describe('App Component', () => {

    // Support for testing component that uses Router
    beforeEachProviders(() => [
      RouteRegistry,
      DirectiveResolver,
      provide(Location, {useClass: SpyLocation}),
      provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent}),
      provide(Router, {useClass: RootRouter})
    ]);

    it('should work',
      injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
        return tcb.overrideTemplate(TestComponent, '<div></div>')
          .createAsync(TestComponent)
          .then((rootTC) =&gt; {
            rootTC.detectChanges();
            let appDOMEl = rootTC.debugElement.children[0].nativeElement;
            expect(DOM.querySelectorAll(appDOMEl, 'app')[0]).toBeDefined();
          });
      }));
  });
}
github tpadjen / ng2-prism / tests / code-renderer.component.spec.ts View on Github external
describe("Shell", () => {

        it('is set if input is present', done => {
          tcb.createAsync(CodeRenderer).then(fixture => {
            let codeRenderer = fixture.componentInstance;
            codeRenderer.shell = 'bash';

            expect(codeRenderer.shellClass).toBe('command-line');
            done();
          })
          .catch(e => done.fail(e));
        });

        it('is not set if input is missing', done => {
          tcb.createAsync(CodeRenderer).then(fixture => {
            let codeRenderer = fixture.componentInstance;

            expect(codeRenderer.shellClass).toBe('');
            done();
github tpadjen / ng2-prism / tests / code-renderer.component.spec.ts View on Github external
describe("Shell", () => {

        it('is set if input is present', done => {
          tcb.createAsync(CodeRenderer).then(fixture => {
            let codeRenderer = fixture.componentInstance;
            codeRenderer.shell = 'bash';

            expect(codeRenderer.shellClass).toBe('command-line');
            done();
          })
          .catch(e => done.fail(e));
        });

        it('is not set if input is missing', done => {
          tcb.createAsync(CodeRenderer).then(fixture => {
            let codeRenderer = fixture.componentInstance;

            expect(codeRenderer.shellClass).toBe('');
            done();
          })
          .catch(e => done.fail(e));
        });

      });
github ritterim / angular2-bank / src / account.spec.ts View on Github external
describe('constructor', () => {
  it('should throw for missing id', () => {
    expect(() => new Account(undefined))
      .toThrowError('id must be provided.');
  });

  it('should allow an id of \'0\'', () => {
    let accountId = '0';

    let account = new Account(accountId);

    expect(account.id).toEqual(accountId);
  });

  it('should throw for negative initialBalance', () => {
    expect(() => new Account('account-1', -1))
      .toThrowError('initialBalance must not be negative.');
  });

  it('should throw for decimal initialBalance', () => {
    let initialBalance = 123.45;

    expect(() => new Account('account-1', initialBalance))
github ritterim / angular2-bank / src / bank.spec.ts View on Github external
describe('getAllAccounts', () => {
  beforeEachProviders(() => {
    Bank.clear();
    bank = new Bank().openAccount(accountId);
  });

  it('should return the complete collection of accounts', () => {
    bank.openAccount('account-2', 0);

    expect(bank.getAllAccounts().length).toEqual(2);
  });
});
github ng-bootstrap / ng-bootstrap / src / pagination / pagination.spec.ts View on Github external
const html =
             '';

         return tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) =&gt; {
           fixture.debugElement.componentInstance.collectionSize = 30;
           fixture.debugElement.componentInstance.pageSize = 5;
           fixture.detectChanges();
           expectPages(fixture.debugElement.nativeElement, ['-« Previous', '+1', '2', '3', '4', '5', '6', '» Next']);

           fixture.debugElement.componentInstance.pageSize = 10;
           fixture.detectChanges();
           expectPages(fixture.debugElement.nativeElement, ['-« Previous', '+1', '2', '3', '» Next']);
         });
       }));

    it('should render and respond to active page change', injectAsync([TestComponentBuilder], (tcb) =&gt; {
         const html = '';

         return tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) =&gt; {
           fixture.debugElement.componentInstance.collectionSize = 30;
           fixture.debugElement.componentInstance.page = 2;
           fixture.detectChanges();
           expectPages(fixture.debugElement.nativeElement, ['« Previous', '1', '+2', '3', '» Next']);

           fixture.debugElement.componentInstance.page = 3;
           fixture.detectChanges();
           expectPages(fixture.debugElement.nativeElement, ['« Previous', '1', '2', '+3', '-» Next']);
         });
       }));

    it('should update selected page model on page no click', injectAsync([TestComponentBuilder], (tcb) =&gt; {
         const html = '';
github ritterim / angular2-bank / src / bank.spec.ts View on Github external
bank = new Bank().openAccount(accountId);
  });

  it('should error if account does not exist', () => {
    let accountIdDoesNotExist = 'does-not-exist';

    expect(() => bank.withdraw(accountIdDoesNotExist, 0))
      .toThrowError(`There was no account with id of '${accountIdDoesNotExist}'.`);
  });

  it('should error for missing amount', () => {
    expect(() => bank.withdraw(accountId, undefined))
      .toThrowError('amount must be specified.');
  });

  it('should error for negative amount', () => {
    let amount = -1;

    expect(() => bank.withdraw(accountId, amount))
      .toThrowError(`The amount specified '${amount}' must not be negative.`);
  });

  it('should error for decimal amount', () => {
    let amount = 123.45;

    expect(() => bank.withdraw(accountId, amount))
      .toThrowError(
        `The amount specified '${amount}' must be an integer ` +
        '(decimals are not supported)');
  });

  it('should error if insufficient funds', () => {
github ng-bootstrap / ng-bootstrap / src / pagination / pagination.spec.ts View on Github external
describe('business logic', () => {

    var paginationCmpt: NgbPagination;

    beforeEach(() => { paginationCmpt = new NgbPagination(); });

    it('should calculate and update no of pages (default page size)', () => {
      paginationCmpt.collectionSize = 100;
      paginationCmpt.onChanges();
      expect(paginationCmpt.pages.length).toEqual(10);

      paginationCmpt.collectionSize = 200;
      paginationCmpt.onChanges();
      expect(paginationCmpt.pages.length).toEqual(20);
    });

    it('should calculate and update no of pages (custom page size)', () => {
      paginationCmpt.collectionSize = 100;
      paginationCmpt.pageSize = 20;
      paginationCmpt.onChanges();
      expect(paginationCmpt.pages.length).toEqual(5);

      paginationCmpt.collectionSize = 200;