Skip to content

Instantly share code, notes, and snippets.

View cakeinpanic's full-sized avatar

Katya Pavlenko cakeinpanic

View GitHub Profile
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,
@cakeinpanic
cakeinpanic / snippet.ts
Last active August 8, 2017 20:51
render custom component
@Component({
selector: 'inner-component',
template: '<div (click)="onClick()">{{someValue}}</div>'
})
export class InputComponent {
@Input() someValue: string;
@Output() onClick = new EventEmitter<any>();
}
@NgModule({
@cakeinpanic
cakeinpanic / someMethod.js
Last active October 7, 2017 22:11
gist for medium
// method we are testing
class MyService {
someMethod() {
Observable.interval(1000)
.subscribe(() => {
this.logger.logObservable();
});
setInterval(() => {
this.logger.logInterval();
@cakeinpanic
cakeinpanic / realInterval.test.js
Last active October 7, 2017 22:14
gist for medium
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);
});
@cakeinpanic
cakeinpanic / setIntervalAmount.js
Last active October 7, 2017 22:15
gist for medium
class MyService {
constructor(private customInterval = 1000) {
}
someMethod() {
Observable.interval(this.customInterval)
.subscribe(() => {
this.logger.logObservable();
});
@cakeinpanic
cakeinpanic / interval.test.js
Last active October 8, 2017 07:14
gist for medium
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();
@cakeinpanic
cakeinpanic / test.sinon.js
Last active October 8, 2017 07:16
gist for medium
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();
// 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(() => {
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))
@cakeinpanic
cakeinpanic / example.js
Last active December 20, 2017 20:42
dependency
class MyService {
sayHello(name: string) {
return 'Hello ' + name;
}
}
class MyComponent {
constructor(private myService) {
}