Skip to content

Commit

Permalink
adding some missing reactive object tests
Browse files Browse the repository at this point in the history
  • Loading branch information
patsissons committed Oct 25, 2016
1 parent 36b7254 commit 154ed4d
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion test/ReactiveObject.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { should } from './setup';

import { Observable } from 'rxjs';
import { Observable, Subject, BehaviorSubject } from 'rxjs';
import { ReactiveObject, registerMember } from '../src/ReactiveObject';

describe('ReactiveObject', () => {
Expand Down Expand Up @@ -198,4 +198,47 @@ describe('ReactiveObject', () => {
child.owner.should.eql(obj);
});
});

describe('name', () => {
it('can only be set once', () => {
const obj = new BasicReactiveObject();

obj.name = 'asdf';
should.throw(() => { obj.name = 'asdf2'; });
});
});

describe('delayChangeNotifications', () => {
class TestObject extends BasicReactiveObject {
public prop1 = this.property<number>();
public prop2 = this.property<number>();
}

it('de-duplicates member changed events by name', () => {
const obj = new TestObject();
const subject = new BehaviorSubject<string[]>(null);
const end = new Subject();

obj.changed
.map(x => x.value.name)
.takeUntil(end)
.toArray()
.subscribe(subject);

Observable.using(
() => obj.delayChangeNotifications(),
x => {
obj.prop1.value = 1;
obj.prop2.value = 2;
obj.prop1.value = 3;

x.unsubscribe();
}
).subscribe();

end.next();
should.exist(subject.value);
subject.value.should.eql([ 'prop1', 'prop2' ]);
});
});
});

0 comments on commit 154ed4d

Please sign in to comment.