Skip to content

Commit

Permalink
test(decorator): multiselector slice changed handler
Browse files Browse the repository at this point in the history
related issue #68
  • Loading branch information
zewa666 committed Oct 3, 2018
1 parent eff5fc7 commit c3968f2
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion test/unit/decorator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Container } from "aurelia-framework";
import { Subscription } from "rxjs";
import { pluck } from "rxjs/operators";
import { pluck, distinctUntilChanged } from "rxjs/operators";

import { Store } from "../../src/store";
import { connectTo } from "../../src/decorator";
Expand Down Expand Up @@ -627,6 +627,34 @@ describe("using decorators", () => {
expect(sut.fooChanged).toHaveBeenCalledWith("targetProp", initialState, "foobar");
});

it("should call changed handler for multiple selectors only when their state slice is affected", async () => {
const { store } = arrange();
const changeOnlyBar = (state: DemoState) => Object.assign({}, state, { bar: "changed" });
store.registerAction("changeOnlyBar", changeOnlyBar);

@connectTo<DemoState>({
selector: {
foo: (store) => store.state.pipe(pluck("foo"), distinctUntilChanged()),
bar: (store) => store.state.pipe(pluck("bar"), distinctUntilChanged())
}
})
class DemoStoreConsumer {
barChanged() { }

fooChanged() { }
}

const sut = new DemoStoreConsumer() as Spied<DemoStoreConsumer>;
const spyFoo = jest.spyOn(sut, "fooChanged");
const spyBar = jest.spyOn(sut, "barChanged");
(sut as any).bind();

await store.dispatch(changeOnlyBar);

expect(spyFoo).toHaveBeenCalledTimes(1);
expect(spyBar).toHaveBeenCalledTimes(2);
});

it("should check whether the method exists before calling it and throw a meaningful error", () => {
arrange();

Expand Down

0 comments on commit c3968f2

Please sign in to comment.