Comments (5)
Duh, your resolved and rejected functions return custom values, instead of the values passed in by the test.
This one works as expected:
const adapter = {
deferred: () => {
let resolve;
let reject;
const promise = new Promise((res, rej) => { resolve = res; reject = rej; });
return {
promise,
reject,
resolve,
};
},
rejected: (reason) => Promise.reject(reason),
resolved: (value) => Promise.resolve(value),
};
from promises-tests.
const Pinky = Promise
module.exports = {
resolved: function(value) {
return Pinky.resolve(value)
},
rejected: function(reason) {
return Pinky.resolve(reason)
},
deferred: function() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let res; let rej
const prom = new Pinky((resolve, reject) => {
res = resolve; rej = reject
})
return {
promise: prom,
resolve: res,
reject: rej,
}
},
}
OK, even though I have changed my code as you mentioned, I still got many errors.
from promises-tests.
node 14.16.0 passed all the tests.
node 16.13.0 randomly failed around 10~16 tests.
1) Uncaught error outside test suite:
Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
2) Uncaught error outside test suite:
Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
3) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an asynchronously-fulfilled custom thenable for an already-rejected promise `then` calls `resolvePromise` synchronously via return from a fulfilled promise:
Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
4) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an asynchronously-fulfilled custom thenable for an already-rejected promise `then` calls `resolvePromise` asynchronously via return from a fulfilled promise:
Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
5) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` Uncaught error outside test suite:
Uncaught TypeError: Cannot read properties of undefined (reading 'currentRetry')
at processImmediate (node:internal/timers:464:21)
6) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an eventually-fulfilled promise for an already-rejected promise `then` calls `resolvePromise` synchronously via return from a fulfilled promise:
Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
7) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an eventually-fulfilled promise for an already-rejected promise `then` calls `resolvePromise` synchronously via return from a rejected promise:
Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
8) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an eventually-fulfilled promise for an already-rejected promise `then` calls `resolvePromise` asynchronously via return from a fulfilled promise:
Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
9) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is an eventually-fulfilled promise for an already-rejected promise `then` calls `resolvePromise` asynchronously via return from a rejected promise:
Uncaught UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".
10) Uncaught error outside test suite:
Uncaught TypeError: Cannot read properties of undefined (reading 'currentRetry')
at processImmediate (node:internal/timers:464:21)
11) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.3: If both `resolvePromise` and `rejectPromise` are called, or multiple calls to the same argument are made, the first call takes precedence, and any further calls are ignored. calling `resolvePromise` synchronously then `rejectPromise` asynchronously Uncaught error outside test suite:
Uncaught TypeError: Cannot set properties of undefined (setting 'state')
at onPromiseRejected (node_modules/promises-aplus-tests/lib/tests/2.3.3.js:108:13)
12) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` Uncaught error outside test suite:
Uncaught TypeError: Cannot read properties of undefined (reading 'currentRetry')
at processImmediate (node:internal/timers:464:21)
13) 2.3.3: Otherwise, if `x` is an object or function, Uncaught error outside test suite:
Uncaught TypeError: Cannot read properties of undefined (reading 'currentRetry')
at processImmediate (node:internal/timers:464:21)
from promises-tests.
% node --version
v20.3.0
794 passing (11s)
14 failing
same 2.3.3 failures
from promises-tests.
It seems that the test suite fails since node 15 because of the unhandledrejection changes.
globalThis.Promise
passes all tests in node 20
& node 18
if an unhandledrejection
listener is added in the adapter.
// adapter.js
module.exports = {
deferred() {
let resolve, reject;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
return {
promise,
resolve,
reject,
};
},
};
require('process').on('unhandledRejection', (err) => { console.debug('unhandledRejection', err) });
872 passing (13s)
from promises-tests.
Related Issues (20)
- 2.2.2.2 fails when resolving synchronously outside of .then's event-loop-turn HOT 12
- Help wanted: Own tests or promises-tests tests? HOT 4
- Test suite passes even if clause 2.3.2 is not implemented HOT 1
- Add test case for very nested promises HOT 1
- mocha test runner failures HOT 7
- Add tests for Promise.all and Promise.race. HOT 1
- Can you assist me in satisfying promises aplus spec 2.2.4 in NodeJS? HOT 2
- How to run tests at requirebin?
- "just create a pull request" HOT 2
- Allow to specify the timeout HOT 3
- Promise.prototype.finally tests HOT 1
- resolve then reject miss test case
- 2.3.3 numberOfTimesThenWasRetrieved should not increment in then getter HOT 1
- Please create 1.x branch
- NPM complains about security issues HOT 1
- RFE: Clarify intent re resolve(promise) HOT 1
- 2.3.3.js `x` is an object with normal Object.prototype
- Error `require`ing adapter file D:\my-promise\my-promise.js HOT 1
- what the purpose of these code is in file 2.1.2.js?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from promises-tests.