Home Reference Source Test Repository

buildDocs/bind.spec.js

  1. import * as tslib_1 from "tslib";
  2. import { expect } from 'chai';
  3. import { Bind } from './bind';
  4. import { Once } from './once';
  5. describe('bind', () => {
  6. it('should bind the context of the method', () => {
  7. let context;
  8. class MyClass {
  9. fn() {
  10. context = this;
  11. }
  12. }
  13. tslib_1.__decorate([
  14. Bind()
  15. ], MyClass.prototype, "fn", null);
  16. const myClass = new MyClass();
  17. const myClass2 = new MyClass();
  18. myClass.fn.call(null);
  19. expect(context).to.equal(myClass);
  20. myClass2.fn.call(null);
  21. expect(context).to.equal(myClass2);
  22. });
  23. it('should bind with other decorators', () => {
  24. let context;
  25. class MyClass {
  26. fn() {
  27. context = this;
  28. }
  29. }
  30. tslib_1.__decorate([
  31. Once(),
  32. Bind()
  33. ], MyClass.prototype, "fn", null);
  34. const myClass = new MyClass();
  35. myClass.fn.call(null);
  36. expect(context).to.equal(myClass);
  37. });
  38. });