admin-vue3/tests/promise-with-resolvers.test...

21 lines
724 B
JavaScript

const test = require('node:test')
const assert = require('node:assert/strict')
test('ensurePromiseWithResolvers installs a compatible polyfill when unavailable', async () => {
const original = Promise.withResolvers
try {
Promise.withResolvers = undefined
const { ensurePromiseWithResolvers } = await import('../src/utils/promiseWithResolvers.ts')
ensurePromiseWithResolvers()
assert.equal(typeof Promise.withResolvers, 'function')
const deferred = Promise.withResolvers()
assert.equal(typeof deferred.promise?.then, 'function')
assert.equal(typeof deferred.resolve, 'function')
assert.equal(typeof deferred.reject, 'function')
} finally {
Promise.withResolvers = original
}
})