Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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');
// })
})
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) => {
rootTC.detectChanges();
let appDOMEl = rootTC.debugElement.children[0].nativeElement;
expect(DOM.querySelectorAll(appDOMEl, 'app')[0]).toBeDefined();
});
}));
});
}
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();
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));
});
});
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))
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);
});
});
const html =
'';
return tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
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) => {
const html = '';
return tcb.overrideTemplate(TestComponent, html).createAsync(TestComponent).then((fixture) => {
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) => {
const html = '';
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', () => {
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;