2015-10-08 18:33:17 -04:00
|
|
|
import {
|
|
|
|
it,
|
|
|
|
iit,
|
|
|
|
xit,
|
|
|
|
describe,
|
|
|
|
ddescribe,
|
|
|
|
xdescribe,
|
|
|
|
expect,
|
2015-12-14 21:51:37 -05:00
|
|
|
fakeAsync,
|
2015-10-08 18:33:17 -04:00
|
|
|
tick,
|
|
|
|
beforeEach,
|
|
|
|
inject,
|
2015-12-08 19:44:04 -05:00
|
|
|
injectAsync,
|
2015-12-10 15:00:48 -05:00
|
|
|
withProviders,
|
2015-10-08 18:33:17 -04:00
|
|
|
beforeEachProviders,
|
|
|
|
TestComponentBuilder
|
2015-10-13 03:29:13 -04:00
|
|
|
} from 'angular2/testing';
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-11-18 18:55:43 -05:00
|
|
|
import {Injectable, bind} from 'angular2/core';
|
|
|
|
import {NgIf} from 'angular2/common';
|
2015-11-23 13:18:04 -05:00
|
|
|
import {Directive, Component, View, ViewMetadata} from 'angular2/core';
|
2015-11-18 21:46:24 -05:00
|
|
|
import {PromiseWrapper} from 'angular2/src/facade/promise';
|
2015-11-05 17:07:57 -05:00
|
|
|
import {XHR} from 'angular2/src/compiler/xhr';
|
2015-11-13 14:21:16 -05:00
|
|
|
import {XHRImpl} from 'angular2/src/platform/browser/xhr_impl';
|
2015-10-08 18:33:17 -04:00
|
|
|
|
|
|
|
// Services, and components for the tests.
|
|
|
|
|
|
|
|
@Component({selector: 'child-comp'})
|
|
|
|
@View({template: `<span>Original {{childBinding}}</span>`, directives: []})
|
|
|
|
@Injectable()
|
|
|
|
class ChildComp {
|
|
|
|
childBinding: string;
|
|
|
|
constructor() { this.childBinding = 'Child'; }
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'child-comp'})
|
|
|
|
@View({template: `<span>Mock</span>`})
|
|
|
|
@Injectable()
|
|
|
|
class MockChildComp {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'parent-comp'})
|
|
|
|
@View({template: `Parent(<child-comp></child-comp>)`, directives: [ChildComp]})
|
|
|
|
@Injectable()
|
|
|
|
class ParentComp {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'my-if-comp'})
|
2015-11-23 19:02:19 -05:00
|
|
|
@View({template: `MyIf(<span *ngIf="showMore">More</span>)`, directives: [NgIf]})
|
2015-10-08 18:33:17 -04:00
|
|
|
@Injectable()
|
|
|
|
class MyIfComp {
|
|
|
|
showMore: boolean = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'child-child-comp'})
|
|
|
|
@View({template: `<span>ChildChild</span>`})
|
|
|
|
@Injectable()
|
|
|
|
class ChildChildComp {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'child-comp'})
|
|
|
|
@View({
|
|
|
|
template: `<span>Original {{childBinding}}(<child-child-comp></child-child-comp>)</span>`,
|
|
|
|
directives: [ChildChildComp]
|
|
|
|
})
|
|
|
|
@Injectable()
|
|
|
|
class ChildWithChildComp {
|
|
|
|
childBinding: string;
|
|
|
|
constructor() { this.childBinding = 'Child'; }
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'child-child-comp'})
|
|
|
|
@View({template: `<span>ChildChild Mock</span>`})
|
|
|
|
@Injectable()
|
|
|
|
class MockChildChildComp {
|
|
|
|
}
|
|
|
|
|
|
|
|
class FancyService {
|
|
|
|
value: string = 'real value';
|
|
|
|
getAsyncValue() { return Promise.resolve('async value'); }
|
|
|
|
}
|
|
|
|
|
|
|
|
class MockFancyService extends FancyService {
|
|
|
|
value: string = 'mocked out value';
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'my-service-comp', providers: [FancyService]})
|
|
|
|
@View({template: `injected value: {{fancyService.value}}`})
|
|
|
|
class TestProvidersComp {
|
|
|
|
constructor(private fancyService: FancyService) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'my-service-comp', viewProviders: [FancyService]})
|
|
|
|
@View({template: `injected value: {{fancyService.value}}`})
|
|
|
|
class TestViewProvidersComp {
|
|
|
|
constructor(private fancyService: FancyService) {}
|
|
|
|
}
|
|
|
|
|
2016-01-20 18:55:30 -05:00
|
|
|
@Component({selector: 'external-template-comp'})
|
|
|
|
@View({templateUrl: '/base/modules/angular2/test/testing/static_assets/test.html'})
|
|
|
|
class ExternalTemplateComp {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({selector: 'bad-template-comp'})
|
|
|
|
@View({templateUrl: 'non-existant.html'})
|
|
|
|
class BadTemplateUrl {
|
|
|
|
}
|
2015-10-08 18:33:17 -04:00
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('angular2 jasmine matchers', () => {
|
|
|
|
describe('toHaveCssClass', () => {
|
|
|
|
it('should assert that the CSS class is present', () => {
|
|
|
|
var el = document.createElement('div');
|
|
|
|
el.classList.add('matias');
|
|
|
|
expect(el).toHaveCssClass('matias');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should assert that the CSS class is not present', () => {
|
|
|
|
var el = document.createElement('div');
|
|
|
|
el.classList.add('matias');
|
|
|
|
expect(el).not.toHaveCssClass('fatias');
|
|
|
|
});
|
|
|
|
});
|
2015-11-17 15:37:39 -05:00
|
|
|
|
|
|
|
describe('toHaveCssStyle', () => {
|
|
|
|
it('should assert that the CSS style is present', () => {
|
|
|
|
var el = document.createElement('div');
|
|
|
|
expect(el).not.toHaveCssStyle('width');
|
|
|
|
|
|
|
|
el.style.setProperty('width', '100px');
|
|
|
|
expect(el).toHaveCssStyle('width');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should assert that the styles are matched against the element', () => {
|
|
|
|
var el = document.createElement('div');
|
|
|
|
expect(el).not.toHaveCssStyle({width: '100px', height: '555px'});
|
|
|
|
|
|
|
|
el.style.setProperty('width', '100px');
|
|
|
|
expect(el).toHaveCssStyle({width: '100px'});
|
|
|
|
expect(el).not.toHaveCssStyle({width: '100px', height: '555px'});
|
|
|
|
|
|
|
|
el.style.setProperty('height', '555px');
|
|
|
|
expect(el).toHaveCssStyle({height: '555px'});
|
|
|
|
expect(el).toHaveCssStyle({width: '100px', height: '555px'});
|
|
|
|
});
|
|
|
|
});
|
2015-10-08 18:33:17 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('using the test injector with the inject helper', () => {
|
|
|
|
it('should run normal tests', () => { expect(true).toEqual(true); });
|
|
|
|
|
|
|
|
it('should run normal async tests', (done) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
expect(true).toEqual(true);
|
|
|
|
done();
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
2015-10-14 12:41:15 -04:00
|
|
|
it('provides a real XHR instance',
|
|
|
|
inject([XHR], (xhr) => { expect(xhr).toBeAnInstanceOf(XHRImpl); }));
|
|
|
|
|
2015-10-08 18:33:17 -04:00
|
|
|
describe('setting up Providers', () => {
|
|
|
|
beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]);
|
|
|
|
|
|
|
|
it('should use set up providers',
|
|
|
|
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
|
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
it('should wait until returned promises', injectAsync([FancyService], (service) => {
|
|
|
|
return service.getAsyncValue().then(
|
|
|
|
(value) => { expect(value).toEqual('async value'); });
|
2015-10-08 18:33:17 -04:00
|
|
|
}));
|
|
|
|
|
2015-12-14 21:51:37 -05:00
|
|
|
it('should allow the use of fakeAsync',
|
|
|
|
inject([FancyService], fakeAsync((service) => {
|
|
|
|
var value;
|
|
|
|
service.getAsyncValue().then(function(val) { value = val; });
|
|
|
|
tick();
|
|
|
|
expect(value).toEqual('async value');
|
|
|
|
})));
|
|
|
|
|
2015-10-08 18:33:17 -04:00
|
|
|
describe('using beforeEach', () => {
|
|
|
|
beforeEach(inject([FancyService],
|
|
|
|
(service) => { service.value = 'value modified in beforeEach'; }));
|
|
|
|
|
|
|
|
it('should use modified providers', inject([FancyService], (service) => {
|
|
|
|
expect(service.value).toEqual('value modified in beforeEach');
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('using async beforeEach', () => {
|
2015-12-08 19:44:04 -05:00
|
|
|
beforeEach(injectAsync([FancyService], (service) => {
|
|
|
|
return service.getAsyncValue().then((value) => { service.value = value; });
|
2015-10-08 18:33:17 -04:00
|
|
|
}));
|
|
|
|
|
|
|
|
it('should use asynchronously modified value',
|
|
|
|
inject([FancyService], (service) => { expect(service.value).toEqual('async value'); }));
|
|
|
|
});
|
|
|
|
});
|
2015-12-10 15:00:48 -05:00
|
|
|
|
|
|
|
describe('per test providers', () => {
|
|
|
|
it('should allow per test providers',
|
|
|
|
withProviders(() => [bind(FancyService).toValue(new FancyService())])
|
|
|
|
.inject([FancyService],
|
|
|
|
(service) => { expect(service.value).toEqual('real value'); }));
|
|
|
|
});
|
2015-10-08 18:33:17 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('errors', () => {
|
|
|
|
var originalJasmineIt: any;
|
|
|
|
var originalJasmineBeforeEach: any;
|
2015-11-18 21:46:24 -05:00
|
|
|
|
2015-10-08 18:33:17 -04:00
|
|
|
var patchJasmineIt = () => {
|
2015-11-18 21:46:24 -05:00
|
|
|
var deferred = PromiseWrapper.completer();
|
2015-10-08 18:33:17 -04:00
|
|
|
originalJasmineIt = jasmine.getEnv().it;
|
|
|
|
jasmine.getEnv().it = (description: string, fn) => {
|
2015-11-18 21:46:24 -05:00
|
|
|
var done = () => { deferred.resolve() };
|
|
|
|
(<any>done).fail = (err) => { deferred.reject(err) };
|
2015-10-08 18:33:17 -04:00
|
|
|
fn(done);
|
|
|
|
return null;
|
2015-11-18 21:46:24 -05:00
|
|
|
};
|
|
|
|
return deferred.promise;
|
2015-10-08 18:33:17 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
var restoreJasmineIt = () => { jasmine.getEnv().it = originalJasmineIt; };
|
|
|
|
|
|
|
|
var patchJasmineBeforeEach = () => {
|
2015-12-08 19:44:04 -05:00
|
|
|
var deferred = PromiseWrapper.completer();
|
2015-10-08 18:33:17 -04:00
|
|
|
originalJasmineBeforeEach = jasmine.getEnv().beforeEach;
|
|
|
|
jasmine.getEnv().beforeEach = (fn: any) => {
|
2015-12-08 19:44:04 -05:00
|
|
|
var done = () => { deferred.resolve() };
|
|
|
|
(<any>done).fail = (err) => { deferred.reject(err) };
|
2015-10-08 18:33:17 -04:00
|
|
|
fn(done);
|
|
|
|
return null;
|
2015-12-08 19:44:04 -05:00
|
|
|
};
|
|
|
|
return deferred.promise;
|
2015-10-08 18:33:17 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
var restoreJasmineBeforeEach =
|
|
|
|
() => { jasmine.getEnv().beforeEach = originalJasmineBeforeEach; }
|
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
it('injectAsync should fail when return was forgotten in it', (done) => {
|
|
|
|
var itPromise = patchJasmineIt();
|
|
|
|
it('forgets to return a proimse', injectAsync([], () => { return true; }));
|
|
|
|
|
|
|
|
itPromise.then(() => { done.fail('Expected function to throw, but it did not'); }, (err) => {
|
|
|
|
expect(err).toEqual(
|
|
|
|
'Error: injectAsync was expected to return a promise, but the returned value was: true');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
restoreJasmineIt();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('inject should fail if a value was returned', (done) => {
|
|
|
|
var itPromise = patchJasmineIt();
|
|
|
|
it('returns a value', inject([], () => { return true; }));
|
|
|
|
|
|
|
|
itPromise.then(() => { done.fail('Expected function to throw, but it did not'); }, (err) => {
|
|
|
|
expect(err).toEqual(
|
|
|
|
'Error: inject returned a value. Did you mean to use injectAsync? Returned value was: true');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
restoreJasmineIt();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('injectAsync should fail when return was forgotten in beforeEach', (done) => {
|
|
|
|
var beforeEachPromise = patchJasmineBeforeEach();
|
|
|
|
beforeEach(injectAsync([], () => { return true; }));
|
|
|
|
|
|
|
|
beforeEachPromise.then(
|
|
|
|
() => { done.fail('Expected function to throw, but it did not'); }, (err) => {
|
|
|
|
expect(err).toEqual(
|
|
|
|
'Error: injectAsync was expected to return a promise, but the returned value was: true');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
restoreJasmineBeforeEach();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('inject should fail if a value was returned in beforeEach', (done) => {
|
|
|
|
var beforeEachPromise = patchJasmineBeforeEach();
|
|
|
|
beforeEach(inject([], () => { return true; }));
|
|
|
|
|
|
|
|
beforeEachPromise.then(
|
|
|
|
() => { done.fail('Expected function to throw, but it did not'); }, (err) => {
|
|
|
|
expect(err).toEqual(
|
|
|
|
'Error: inject returned a value. Did you mean to use injectAsync? Returned value was: true');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
restoreJasmineBeforeEach();
|
|
|
|
});
|
|
|
|
|
2015-11-18 21:46:24 -05:00
|
|
|
it('should fail when an error occurs inside inject', (done) => {
|
|
|
|
var itPromise = patchJasmineIt();
|
|
|
|
it('throws an error', inject([], () => { throw new Error('foo'); }));
|
|
|
|
|
|
|
|
itPromise.then(() => { done.fail('Expected function to throw, but it did not'); }, (err) => {
|
|
|
|
expect(err.message).toEqual('foo');
|
|
|
|
done();
|
|
|
|
});
|
2015-10-08 18:33:17 -04:00
|
|
|
restoreJasmineIt();
|
|
|
|
});
|
|
|
|
|
2016-01-20 18:55:30 -05:00
|
|
|
// TODO(juliemr): reenable this test when we are using a test zone and can capture this error.
|
|
|
|
xit('should fail when an asynchronous error is thrown', (done) => {
|
2015-11-18 21:46:24 -05:00
|
|
|
var itPromise = patchJasmineIt();
|
|
|
|
|
|
|
|
it('throws an async error',
|
2016-01-20 18:55:30 -05:00
|
|
|
injectAsync([], () => { setTimeout(() => { throw new Error('bar'); }, 0); }));
|
2015-11-18 21:46:24 -05:00
|
|
|
|
|
|
|
itPromise.then(() => { done.fail('Expected test to fail, but it did not'); }, (err) => {
|
|
|
|
expect(err.message).toEqual('bar');
|
|
|
|
done();
|
|
|
|
});
|
2015-10-08 18:33:17 -04:00
|
|
|
restoreJasmineIt();
|
|
|
|
});
|
|
|
|
|
2015-11-18 21:46:24 -05:00
|
|
|
it('should fail when a returned promise is rejected', (done) => {
|
|
|
|
var itPromise = patchJasmineIt();
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
it('should fail with an error from a promise', injectAsync([], () => {
|
2015-11-18 21:46:24 -05:00
|
|
|
var deferred = PromiseWrapper.completer();
|
|
|
|
var p = deferred.promise.then(() => { expect(1).toEqual(2); });
|
|
|
|
|
|
|
|
deferred.reject('baz');
|
|
|
|
return p;
|
|
|
|
}));
|
|
|
|
|
|
|
|
itPromise.then(() => { done.fail('Expected test to fail, but it did not'); }, (err) => {
|
|
|
|
expect(err).toEqual('baz');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
restoreJasmineIt();
|
2015-10-08 18:33:17 -04:00
|
|
|
});
|
|
|
|
|
2016-01-20 18:55:30 -05:00
|
|
|
it('should fail when an XHR fails', (done) => {
|
|
|
|
var itPromise = patchJasmineIt();
|
|
|
|
|
|
|
|
it('should fail with an error from a promise',
|
|
|
|
injectAsync([TestComponentBuilder], (tcb) => { return tcb.createAsync(BadTemplateUrl); }));
|
|
|
|
|
|
|
|
itPromise.then(() => { done.fail('Expected test to fail, but it did not'); }, (err) => {
|
|
|
|
expect(err).toEqual('Failed to load non-existant.html');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
restoreJasmineIt();
|
2016-01-27 17:39:47 -05:00
|
|
|
}, 10000);
|
2016-01-20 18:55:30 -05:00
|
|
|
|
2015-10-08 18:33:17 -04:00
|
|
|
describe('using beforeEachProviders', () => {
|
|
|
|
beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]);
|
|
|
|
|
|
|
|
beforeEach(
|
|
|
|
inject([FancyService], (service) => { expect(service.value).toEqual('real value'); }));
|
|
|
|
|
|
|
|
describe('nested beforeEachProviders', () => {
|
|
|
|
|
|
|
|
it('should fail when the injector has already been used', () => {
|
2015-12-08 19:44:04 -05:00
|
|
|
patchJasmineBeforeEach();
|
2015-10-08 18:33:17 -04:00
|
|
|
expect(() => {
|
|
|
|
beforeEachProviders(() => [bind(FancyService).toValue(new FancyService())]);
|
|
|
|
})
|
|
|
|
.toThrowError('beforeEachProviders was called after the injector had been used ' +
|
|
|
|
'in a beforeEach or it block. This invalidates the test injector');
|
|
|
|
restoreJasmineBeforeEach();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('test component builder', function() {
|
|
|
|
it('should instantiate a component with valid DOM',
|
2015-12-08 19:44:04 -05:00
|
|
|
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
return tcb.createAsync(ChildComp).then((componentFixture) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
componentFixture.detectChanges();
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
expect(componentFixture.debugElement.nativeElement).toHaveText('Original Child');
|
2015-10-08 18:33:17 -04:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should allow changing members of the component',
|
2015-12-08 19:44:04 -05:00
|
|
|
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
return tcb.createAsync(MyIfComp).then((componentFixture) => {
|
2015-10-31 12:50:19 -04:00
|
|
|
componentFixture.detectChanges();
|
|
|
|
expect(componentFixture.debugElement.nativeElement).toHaveText('MyIf()');
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-10-31 12:50:19 -04:00
|
|
|
componentFixture.debugElement.componentInstance.showMore = true;
|
|
|
|
componentFixture.detectChanges();
|
|
|
|
expect(componentFixture.debugElement.nativeElement).toHaveText('MyIf(More)');
|
2015-10-08 18:33:17 -04:00
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
it('should override a template',
|
|
|
|
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
return tcb.overrideTemplate(MockChildComp, '<span>Mock</span>')
|
2015-10-08 18:33:17 -04:00
|
|
|
.createAsync(MockChildComp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((componentFixture) => {
|
|
|
|
componentFixture.detectChanges();
|
|
|
|
expect(componentFixture.debugElement.nativeElement).toHaveText('Mock');
|
2015-10-08 18:33:17 -04:00
|
|
|
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
it('should override a view',
|
|
|
|
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
return tcb.overrideView(
|
|
|
|
ChildComp,
|
|
|
|
new ViewMetadata({template: '<span>Modified {{childBinding}}</span>'}))
|
2015-10-08 18:33:17 -04:00
|
|
|
.createAsync(ChildComp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((componentFixture) => {
|
|
|
|
componentFixture.detectChanges();
|
|
|
|
expect(componentFixture.debugElement.nativeElement).toHaveText('Modified Child');
|
2015-10-08 18:33:17 -04:00
|
|
|
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should override component dependencies',
|
2015-12-08 19:44:04 -05:00
|
|
|
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
return tcb.overrideDirective(ParentComp, ChildComp, MockChildComp)
|
2015-10-08 18:33:17 -04:00
|
|
|
.createAsync(ParentComp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((componentFixture) => {
|
|
|
|
componentFixture.detectChanges();
|
|
|
|
expect(componentFixture.debugElement.nativeElement).toHaveText('Parent(Mock)');
|
2015-10-08 18:33:17 -04:00
|
|
|
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it("should override child component's dependencies",
|
2015-12-08 19:44:04 -05:00
|
|
|
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
return tcb.overrideDirective(ParentComp, ChildComp, ChildWithChildComp)
|
2015-10-08 18:33:17 -04:00
|
|
|
.overrideDirective(ChildWithChildComp, ChildChildComp, MockChildChildComp)
|
|
|
|
.createAsync(ParentComp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((componentFixture) => {
|
|
|
|
componentFixture.detectChanges();
|
|
|
|
expect(componentFixture.debugElement.nativeElement)
|
2015-10-08 18:33:17 -04:00
|
|
|
.toHaveText('Parent(Original Child(ChildChild Mock))');
|
|
|
|
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
it('should override a provider',
|
|
|
|
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
return tcb.overrideProviders(TestProvidersComp,
|
|
|
|
[bind(FancyService).toClass(MockFancyService)])
|
2015-10-08 18:33:17 -04:00
|
|
|
.createAsync(TestProvidersComp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((componentFixture) => {
|
|
|
|
componentFixture.detectChanges();
|
|
|
|
expect(componentFixture.debugElement.nativeElement)
|
2015-10-08 18:33:17 -04:00
|
|
|
.toHaveText('injected value: mocked out value');
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
it('should override a viewProvider',
|
2015-12-08 19:44:04 -05:00
|
|
|
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
2015-10-08 18:33:17 -04:00
|
|
|
|
2015-12-08 19:44:04 -05:00
|
|
|
return tcb.overrideViewProviders(TestViewProvidersComp,
|
|
|
|
[bind(FancyService).toClass(MockFancyService)])
|
2015-10-08 18:33:17 -04:00
|
|
|
.createAsync(TestViewProvidersComp)
|
2015-10-31 12:50:19 -04:00
|
|
|
.then((componentFixture) => {
|
|
|
|
componentFixture.detectChanges();
|
|
|
|
expect(componentFixture.debugElement.nativeElement)
|
2015-10-08 18:33:17 -04:00
|
|
|
.toHaveText('injected value: mocked out value');
|
|
|
|
});
|
|
|
|
}));
|
2016-01-20 18:55:30 -05:00
|
|
|
|
|
|
|
it('should allow an external templateUrl',
|
|
|
|
injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
|
|
|
|
|
|
|
return tcb.createAsync(ExternalTemplateComp)
|
|
|
|
.then((componentFixture) => {
|
|
|
|
componentFixture.detectChanges();
|
|
|
|
expect(componentFixture.debugElement.nativeElement)
|
|
|
|
.toHaveText('from external template\n');
|
|
|
|
});
|
2016-02-25 17:27:32 -05:00
|
|
|
}), 10000); // Long timeout here because this test makes an actual XHR, and is slow on Edge.
|
2015-10-08 18:33:17 -04:00
|
|
|
});
|
|
|
|
}
|