Skip to content

Commit

Permalink
fix(decorator): use component instance instead of prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Malkevich committed Jan 10, 2019
1 parent 8425bb2 commit 209ef22
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions __tests__/decorator.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { EMPTY, Subject } from 'rxjs';

import * as untilDestroyedObj from '../src/take-until-destroy';

import { WithUntilDestroyed } from '../src/decorator';
import * as untilDestroyedObj from '../src/take-until-destroy';

describe('@WithUntilDestroyed decorator', () => {
it('should throw when applied on non Observable prop', () => {
Expand All @@ -14,7 +13,7 @@ describe('@WithUntilDestroyed decorator', () => {
expect(() => new Test()).toThrowError();
});

it('should call `untilDestroyed()` with target prototype and `destroyMethodName` on setter', () => {
it('should call `untilDestroyed()` with instance and `destroyMethodName` on setter', () => {
const untilDestroyedSpy = spyOn(
untilDestroyedObj,
'untilDestroyed',
Expand All @@ -29,9 +28,9 @@ describe('@WithUntilDestroyed decorator', () => {

expect(untilDestroyedSpy).not.toHaveBeenCalled();

new Test();
const test = new Test();

expect(untilDestroyedSpy).toHaveBeenCalledWith(Test.prototype, 'destroy');
expect(untilDestroyedSpy).toHaveBeenCalledWith(test, 'destroy');
});

it('should unsubscribe when `destroyMethodName` was called', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function WithUntilDestroyed(

function setter(newVal) {
if (isObservable(newVal)) {
val = newVal.pipe(untilDestroyed(target, destroyMethodName));
val = newVal.pipe(untilDestroyed(this, destroyMethodName));
} else {
throw Error(
`WithUntilDestroyed: Property ${String(propKey)} on ${
Expand Down

0 comments on commit 209ef22

Please sign in to comment.