Skip to content

Commit

Permalink
Tests WIP 29 (spaces to tabs)
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jul 8, 2016
1 parent f8ef855 commit 8981508
Show file tree
Hide file tree
Showing 28 changed files with 1,404 additions and 1,404 deletions.
262 changes: 131 additions & 131 deletions test/init/patched.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,104 +7,104 @@

// Modules
var expect = require('chai').expect,
_ = require('lodash');
_ = require('lodash');

// Imports
var runTests = require('../support');

// Run tests

runTests('Patch', function(u, Promise) {
describe('patches', function() {
describe('static method', function() {
var ignore = [
'onPossiblyUnhandledRejection',
'onUnhandledRejectionHandled',
'longStackTraces',
'hasLongStackTraces',
'config',
'getNewLibraryCopy',
'is',
'fromCallback',
'fromNode',
'promisify',
'promisifyAll',
'all',
'props',
'any',
'some',
'race',
'resolve',
'fulfilled',
'cast',
'reject',
'rejected',
'setScheduler',
'method',
'try',
'attempt',
'bind',
'settle',
'delay',
'defer',
'pending',
'clone' // comes from bluebird2 / bluebird3 libraries not bluebird itself
];

checkPatched(Promise, ignore);
});

describe('prototype method', function() {
var ignore = [
'catch', // TODO only ignore on bluebird v3
'caught', // TODO only ignore on bluebird v3
'error',
'all',
'props',
'any',
'some',
'race',
'bind',
'isFulfilled',
'isRejected',
'isPending',
'isCancelled',
'isResolved',
'value',
'reason',
'reflect',
'settle',
'delay',
'timeout',
'get',
'return',
'thenReturn',
'throw',
'thenThrow',
'catchReturn',
'catchThrow',
'cancel',
'break',
'isCancellable',
'cancellable',
'uncancellable',
'suppressUnhandledRejections',
'toString',
'toJSON'
];
checkPatched(Promise.prototype, ignore);
});
});

describe('maintains method equality', function() {
it('static methods', function() {
checkEqual(Promise, u.UnpatchedPromise);
});

it('prototype methods', function() {
checkEqual(Promise.prototype, u.UnpatchedPromise.prototype);
});
});
describe('patches', function() {
describe('static method', function() {
var ignore = [
'onPossiblyUnhandledRejection',
'onUnhandledRejectionHandled',
'longStackTraces',
'hasLongStackTraces',
'config',
'getNewLibraryCopy',
'is',
'fromCallback',
'fromNode',
'promisify',
'promisifyAll',
'all',
'props',
'any',
'some',
'race',
'resolve',
'fulfilled',
'cast',
'reject',
'rejected',
'setScheduler',
'method',
'try',
'attempt',
'bind',
'settle',
'delay',
'defer',
'pending',
'clone' // comes from bluebird2 / bluebird3 libraries not bluebird itself
];

checkPatched(Promise, ignore);
});

describe('prototype method', function() {
var ignore = [
'catch', // TODO only ignore on bluebird v3
'caught', // TODO only ignore on bluebird v3
'error',
'all',
'props',
'any',
'some',
'race',
'bind',
'isFulfilled',
'isRejected',
'isPending',
'isCancelled',
'isResolved',
'value',
'reason',
'reflect',
'settle',
'delay',
'timeout',
'get',
'return',
'thenReturn',
'throw',
'thenThrow',
'catchReturn',
'catchThrow',
'cancel',
'break',
'isCancellable',
'cancellable',
'uncancellable',
'suppressUnhandledRejections',
'toString',
'toJSON'
];
checkPatched(Promise.prototype, ignore);
});
});

describe('maintains method equality', function() {
it('static methods', function() {
checkEqual(Promise, u.UnpatchedPromise);
});

it('prototype methods', function() {
checkEqual(Promise.prototype, u.UnpatchedPromise.prototype);
});
});
});

/**
Expand All @@ -117,15 +117,15 @@ runTests('Patch', function(u, Promise) {
* @returns {undefined}
*/
function checkPatched(obj, ignore) {
_.forIn(obj, function(method, name) {
if (name.match(/^[A-Z_]/)) return;
if (ignore.indexOf(name) !== -1) return;
if (typeof method !== 'function') return;

it(name, function() {
if (!method.__wrapped) throw new Error("'" + name + "' method not patched"); // jshint ignore:line
});
});
_.forIn(obj, function(method, name) {
if (name.match(/^[A-Z_]/)) return;
if (ignore.indexOf(name) !== -1) return;
if (typeof method !== 'function') return;

it(name, function() {
if (!method.__wrapped) throw new Error("'" + name + "' method not patched"); // jshint ignore:line
});
});
}

/**
Expand All @@ -136,46 +136,46 @@ function checkPatched(obj, ignore) {
* @throws {AssertionError} - If patching has changed things
*/
function checkEqual(obj, unpatchedObj) {
var matchesUnpatched = getEquals(unpatchedObj);
var matchesPatched = getEquals(obj);
var matchesUnpatched = getEquals(unpatchedObj);
var matchesPatched = getEquals(obj);

expect(matchesPatched).to.deep.equal(matchesUnpatched);
expect(matchesPatched).to.deep.equal(matchesUnpatched);
}

/**
* Loop through all object's methods and return array of any which are equal to each other.
* e.g. `obj.method1 == obj.method2, obj.method3 == obj.method4`
* -> [ ['method1', 'method2'], ['method3', 'method4'] ]
* -> [ ['method1', 'method2'], ['method3', 'method4'] ]
*
* @param {Object} obj - Object whose methods to check
* @returns {Array} - Array of matches
*/
function getEquals(obj) {
var keys = Object.keys(obj).sort();

var matches = [],
matched = [];
keys.forEach(function(key) {
var method = obj[key];
if (typeof method !== 'function') return;
if (matches.indexOf(key) !== -1) return;

var thisMatches = [];
keys.forEach(function(otherKey) {
if (otherKey <= key) return;

var otherMethod = obj[otherKey];
if (method === otherMethod) {
thisMatches.push(otherKey);
matched.push(otherKey);
}
});

if (thisMatches.length) {
thisMatches.unshift(key);
matches.push(thisMatches);
}
});

return matches;
var keys = Object.keys(obj).sort();

var matches = [],
matched = [];
keys.forEach(function(key) {
var method = obj[key];
if (typeof method !== 'function') return;
if (matches.indexOf(key) !== -1) return;

var thisMatches = [];
keys.forEach(function(otherKey) {
if (otherKey <= key) return;

var otherMethod = obj[otherKey];
if (method === otherMethod) {
thisMatches.push(otherKey);
matched.push(otherKey);
}
});

if (thisMatches.length) {
thisMatches.unshift(key);
matches.push(thisMatches);
}
});

return matches;
}
12 changes: 6 additions & 6 deletions test/methods/bind.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ var runTests = require('../support');
// Run tests

runTests('Promise.bind()', function(u, Promise) {
u.testSetStaticMethodReceivingValueReturnsPromise(function(value) {
return Promise.bind(value);
});
u.testSetStaticMethodReceivingValueReturnsPromise(function(value) {
return Promise.bind(value);
});
});

runTests('.bind()', function(u) {
u.testSetProtoMethodReceivingValueReturnsPromise(function(p, value) {
return p.bind(value);
});
u.testSetProtoMethodReceivingValueReturnsPromise(function(p, value) {
return p.bind(value);
});
});
32 changes: 16 additions & 16 deletions test/methods/catch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ var runTests = require('../support');
// Run tests

runTests('.catch()', function(u) {
describe('with 1st arg', function() {
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.catch(handler);
}, {catches: true});
});
describe('with 1st arg', function() {
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.catch(handler);
}, {catches: true});
});

describe('with 2nd arg', function() {
// NB In bluebird v3 handler is not bound when on 2nd arg.
// `.catch()` calls `.then()` synchronously but with proxy handler.
// No way to test for binding.
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.catch(Error, handler);
}, {catches: true, noUndefined: true, noBindTest: (u.bluebirdVersion === 3)});
});
describe('with 2nd arg', function() {
// NB In bluebird v3 handler is not bound when on 2nd arg.
// `.catch()` calls `.then()` synchronously but with proxy handler.
// No way to test for binding.
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.catch(Error, handler);
}, {catches: true, noUndefined: true, noBindTest: (u.bluebirdVersion === 3)});
});
});

runTests('.caught()', function(u, Promise) { // jshint ignore:line
it('is alias of .catch()', function() {
expect(Promise.prototype.caught).to.equal(Promise.prototype.catch);
});
it('is alias of .catch()', function() {
expect(Promise.prototype.caught).to.equal(Promise.prototype.catch);
});
});
Loading

0 comments on commit 8981508

Please sign in to comment.