Skip to content

Commit

Permalink
Increase line coverage to 100% and fix a disposal bug
Browse files Browse the repository at this point in the history
  • Loading branch information
azz committed May 22, 2016
1 parent 634383f commit 898e021
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ Written in plain ECMAScript 5, safe to load in the browser without any transform

## Tests

Fully unit tested with mocha, chai and jsdom. Run with:
Fully unit tested with mocha, chai, sinon and jsdom. Run with:

```
$ npm test
$ npm run test-node # to test in Node.JS
$ npm run test-phantom # to test in PhantomJS
```

## License
Expand Down
2 changes: 1 addition & 1 deletion ko-Rx.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
var dispose = computed.dispose;
computed.dispose = function () {
rxDisposable.dispose();
dispose.apply(rxObservable, arguments);
dispose.apply(computed, arguments);
};

return computed;
Expand Down
27 changes: 26 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ describe('ko-Rx - environment: ' + (hasRequire ? 'NodeJS' : 'PhantomJS'), functi
var rxObservable = koComputed.toRxObservable();
expect(Rx.Observable.isObservable(rxObservable)).to.be.true;
});

it('calls onCompleted on Rx.Observable when underlying ko.computed is disposed', function () {
var koComputed = ko.computed({
read: function () {
return koObservable();
}
});
var rxObservable = koComputed.toRxObservable();
var spyCompleted = sinon.spy();
rxObservable.subscribe(function () {}, function () {}, spyCompleted);
koComputed.dispose();
expect(spyCompleted.called).to.be.true;
});
});

describe('Rx.Observable to ko.computed', function () {
Expand Down Expand Up @@ -142,7 +155,19 @@ describe('ko-Rx - environment: ' + (hasRequire ? 'NodeJS' : 'PhantomJS'), functi
expect(spy.calledWith(1)).to.be.true;
});

it('stops receiving after subscription disposal', function () {
it('stops receiving after computed disposal', function () {
var koComputed = rxSubject.toKnockoutComputed();
expect(ko.isSubscribable(koComputed)).to.be.true;
var spy = sinon.spy();
var subscription = koComputed.subscribe(spy);
rxSubject.onNext(0);
expect(spy.calledWith(0)).to.be.true;
koComputed.dispose();
rxSubject.onNext(1);
expect(spy.calledWith(1)).to.be.false;
});

it('stops receiving after computed subscription disposal', function () {
var koComputed = rxSubject.toKnockoutComputed();
expect(ko.isSubscribable(koComputed)).to.be.true;
var spy = sinon.spy();
Expand Down

0 comments on commit 898e021

Please sign in to comment.