Skip to content

Commit 231a5a8

Browse files
committed
Tests for removePost
1 parent 6dc7b05 commit 231a5a8

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test.js

+46
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,52 @@ module.exports = {
626626
should.strictEqual(undefined, a.preValueOne);
627627
should.strictEqual(undefined, a.preValueTwo);
628628
},
629+
630+
'should be able to remove a particular post': function () {
631+
var A = function () {}
632+
, postTwo;
633+
_.extend(A, hooks);
634+
A.hook('save', function () {
635+
this.value = 1;
636+
});
637+
A.post('save', function (next) {
638+
this.postValueOne = 2;
639+
next();
640+
});
641+
A.post('save', postTwo = function (next) {
642+
this.postValueTwo = 4;
643+
next();
644+
});
645+
A.removePost('save', postTwo);
646+
var a = new A();
647+
a.save();
648+
a.value.should.equal(1);
649+
a.postValueOne.should.equal(2);
650+
should.strictEqual(undefined, a.postValueTwo);
651+
},
652+
653+
'should be able to remove all posts associated with a hook': function () {
654+
var A = function () {};
655+
_.extend(A, hooks);
656+
A.hook('save', function () {
657+
this.value = 1;
658+
});
659+
A.post('save', function (next) {
660+
this.postValueOne = 2;
661+
next();
662+
});
663+
A.post('save', function (next) {
664+
this.postValueTwo = 4;
665+
next();
666+
});
667+
A.removePost('save');
668+
var a = new A();
669+
a.save();
670+
a.value.should.equal(1);
671+
should.strictEqual(undefined, a.postValueOne);
672+
should.strictEqual(undefined, a.postValueTwo);
673+
},
674+
629675

630676
'#pre should lazily make a method hookable': function () {
631677
var A = function () {};

0 commit comments

Comments
 (0)