How to use the promise-polyfill.prototype function in promise-polyfill

To help you get started, we’ve selected a few promise-polyfill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github taylorhakes / promise-mock / src / index.js View on Github external
import Promise from 'promise-polyfill';

var root = typeof window === 'undefined' ? global : window;


function PromiseMock() {
  Promise.apply(this, arguments);
}
PromiseMock.prototype = Object.create(Promise.prototype);
Object.keys(Promise).forEach(function (key) {
  PromiseMock[key] = Promise[key];
});

// Queue of waiting callbacks
PromiseMock.waiting = [];


/**
 * Execute a pending Promise
 */
PromiseMock.run = function run(count) {
  var runTimes = count ? count : 1;

  if (PromiseMock.waiting.length === 0) {
    throw new Error('No Promises waiting. Can\'t Promise.run()')