Skip to content

Commit

Permalink
chore: add es6 promise (#1356)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeyyy authored Feb 12, 2019
1 parent e795f7d commit 8e85ae2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/core/imports/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
/* global axe */

// Note: the below is run via `browserify` build task - `build/imports-generator` and output into the `tmp` directory.
/**
* Note:
* Npm script -> `imports-gen` runs browserify
* to pull in the required dependencies.
*/

/**
* Polyfill `Promise`
* Reference: https://www.npmjs.com/package/es6-promise
*/
require('es6-promise').polyfill();

/**
* Namespace for imports which holds globals of external dependencies.
* Namespace `axe.imports` which holds required external dependencies
*
* @namespace imports
* @memberof axe
*/
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"clone": "~2.1.1",
"css-selector-parser": "^1.3.0",
"dot": "~1.1.2",
"es6-promise": "^4.2.5",
"eslint": "^5.9.0",
"eslint-config-prettier": "^3.4.0",
"execa": "^1.0.0",
Expand Down
40 changes: 40 additions & 0 deletions test/integration/full/umd/umd-window.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,46 @@ describe('UMD window', function() {
assert.property(window, 'axe');
});

it('should expose Promise as a property of window', function() {
assert.property(window, 'Promise');
});

it('should resolve Promise(s)', function(done) {
var p1 = new Promise(function(resolve) {
setTimeout(function() {
resolve('Hello');
});
});
var p2 = new Promise(function(resolve) {
setTimeout(function() {
resolve('World!');
});
});
Promise.all([p1, p2])
.then(function(values) {
assert.lengthOf(values, 2);
assert.equal(values.join(' '), 'Hello World!');
})
.catch(function() {
done(new Error('Expected to resolve.'));
})
.finally(done);
});
it('should reject Promise', function(done) {
new Promise(function(resolve, reject) {
setTimeout(function() {
reject(new Error('Boom!'));
});
})
.then(function() {
done(new Error('Expected to reject.'));
})
.catch(function(err) {
assert.isDefined(err);
done();
});
});

it('should ensure axe has prototype chained keys', function() {
assert.hasAnyKeys(axe, ['utils', 'commons', 'core']);
});
Expand Down

0 comments on commit 8e85ae2

Please sign in to comment.