Skip to content
This repository was archived by the owner on Sep 25, 2024. It is now read-only.

Commit f804cfd

Browse files
committed
Merge pull request #8 from arb/fix-bug
Fixed bug where this basically didn't work at all.
2 parents b8cf04b + a8262a6 commit f804cfd

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

.eslintignore

-2
This file was deleted.

lib/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var internals = {
1010
internals.store.lookUp = function (obj, method) {
1111
var i = this.length;
1212
var lookup;
13-
while (i-- && !lookup) {
13+
while (!lookup && i--) {
1414
var item = this[i];
1515

1616
if (item.obj === obj && item.method === method) {
@@ -40,8 +40,9 @@ exports.replace = function (obj, method, fn) {
4040
var result = {
4141
original: obj[method].bind(obj),
4242
restore: function () {
43-
var find = internals.store.lookUp(this._stand.obj, this._stand.method);
43+
var find = internals.store.lookUp(obj, method);
4444
internals.store.splice(find.index, 1);
45+
obj[method] = this.original;
4546
},
4647
_stand: stand
4748
};

test/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('stand-in', function () {
2525
it('correctly restores a replaced method', function (done) {
2626
var foo = {
2727
bar: function (valueone, valuetwo) {
28-
console.log('%s, %s');
28+
throw new Error('this is a test error');
2929
}
3030
};
3131

@@ -35,7 +35,7 @@ describe('stand-in', function () {
3535

3636
replace.restore();
3737

38-
expect(foo.bar).to.deep.equal(foo.bar);
38+
expect(foo.bar).to.throw(Error, 'this is a test error');
3939
done();
4040
});
4141

0 commit comments

Comments
 (0)