This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var webpackConfig = require('../webpack.config.js'); | |
module.exports = function () { | |
autoWatch: true, | |
frameworks: ['jasmine'], | |
preprocessors: { | |
'../app/**/*.js': ['webpack'], | |
'../app/**/scripts/**/*.js': ['coverage'] | |
}, | |
webpack: { | |
resolve: webpackConfig.resolve, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'inner-component', | |
template: '<div (click)="onClick()">{{someValue}}</div>' | |
}) | |
export class InputComponent { | |
@Input() someValue: string; | |
@Output() onClick = new EventEmitter<any>(); | |
} | |
@NgModule({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// method we are testing | |
class MyService { | |
someMethod() { | |
Observable.interval(1000) | |
.subscribe(() => { | |
this.logger.logObservable(); | |
}); | |
setInterval(() => { | |
this.logger.logInterval(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('someMethod would be ran with iterator each second', (done) => { | |
myService.someMethod(); | |
setTimeout(() => { | |
expect(logger.logObservable).toHaveBeenCalledTimes(2); | |
expect(logger.logInterval).toHaveBeenCalledTimes(1); | |
done(); | |
}, 2 * 1000); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyService { | |
constructor(private customInterval = 1000) { | |
} | |
someMethod() { | |
Observable.interval(this.customInterval) | |
.subscribe(() => { | |
this.logger.logObservable(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('someMethod would be ran with iterator each second', fakeAsync(() => { | |
myService.someMethod(); | |
tick(2 * 1000); | |
expect(logger.logObservable).toHaveBeenCalledTimes(2); | |
expect(logger.logInterval).toHaveBeenCalledTimes(1); | |
// tell jasmine we don't need to emulate async anymore in this case | |
discardPeriodicTasks(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('someMethod would be ran with iterator each second', () => { | |
const clock = <any>sinon.useFakeTimers(0); | |
myService.someMethod(); | |
clock.tick(2 * 1000); | |
expect(logger.logObservable).toHaveBeenCalledTimes(2); | |
expect(logger.logInterval).toHaveBeenCalledTimes(1); | |
// tell sinon to restore global timers for other tests | |
clock.restore(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/angular/angular/issues/10127#issuecomment-247873713 | |
it('should run async test with successful delayed Observable', fakeAsync(() => { | |
let actuallyDone = false; | |
let currentTime = 0; | |
spyOn(Scheduler.async, 'now').and.callFake(() => currentTime); | |
let source = Observable.of(true).delay(10); | |
source.subscribe(() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DELAY = 1000; | |
Rx.Observable.of(1, 2, 3) | |
.delay(DELAY) | |
.subscribe((data) => console.log(data)) | |
Rx.Observable.of(1, 2, 3) | |
.flatMap((data) => Rx.Observable.interval(DELAY).first().map(() => data)) | |
.subscribe((data) => console.log(data)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyService { | |
sayHello(name: string) { | |
return 'Hello ' + name; | |
} | |
} | |
class MyComponent { | |
constructor(private myService) { | |
} |
OlderNewer