@js-bits/xpromise
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -46,3 +46,5 @@ import enumerate from '@js-bits/enumerate'; | ||
if (this[ø.executor]) { | ||
this[ø.executor](this[ø.resolve], this[ø.reject], ...args); | ||
const resolve = this.resolve.bind(this); | ||
const reject = this.reject.bind(this); | ||
this[ø.executor](resolve, reject, ...args); | ||
this[ø.executor] = undefined; | ||
@@ -49,0 +51,0 @@ } |
@@ -0,1 +1,3 @@ | ||
/* eslint-disable max-classes-per-file */ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { jest } from '@jest/globals'; | ||
@@ -134,2 +136,51 @@ import { cyan } from '@js-bits/log-in-color'; | ||
}); | ||
describe('resolve/reject binding', () => { | ||
test('resolve', async () => { | ||
expect.assertions(3); | ||
const resolveFunc = jest.fn(); | ||
class ResolvedPromise extends ExtendablePromise { | ||
constructor(...args) { | ||
super((resolve, reject) => { | ||
resolve(true); | ||
}, ...args); | ||
this.execute(); | ||
} | ||
resolve(...args) { | ||
resolveFunc(...args); | ||
super.resolve(...args); | ||
} | ||
} | ||
const resolvedPromise = new ResolvedPromise(); | ||
return resolvedPromise.then(result => { | ||
expect(result).toEqual(true); | ||
expect(resolveFunc).toHaveBeenCalledWith(true); | ||
expect(resolveFunc).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
test('reject', async () => { | ||
expect.assertions(2); | ||
const rejectFunc = jest.fn(); | ||
class RejectedPromise extends ExtendablePromise { | ||
constructor(...args) { | ||
super((resolve, reject) => { | ||
reject(new Error('Rejected Promise')); | ||
}, ...args); | ||
this.execute(); | ||
} | ||
reject(...args) { | ||
rejectFunc(...args); | ||
super.reject(...args); | ||
} | ||
} | ||
const rejectedPromise = new RejectedPromise(); | ||
return rejectedPromise.catch(reason => { | ||
expect(reason.message).toEqual('Rejected Promise'); | ||
expect(rejectFunc).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "@js-bits/xpromise", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Extendable Promise", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9744
254