Skip to content

Commit

Permalink
Pull in the debugging from debug/failingChromeHeadlessTests to see if…
Browse files Browse the repository at this point in the history
… it fails here
  • Loading branch information
papandreou committed Feb 9, 2020
1 parent 7067a53 commit 20824e4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
10 changes: 10 additions & 0 deletions lib/assertions.js
Expand Up @@ -453,6 +453,16 @@ module.exports = expect => {
expect.addAssertion(
'<object> to have [own] properties <object>',
(expect, subject, properties) => {
console.log('properties', properties);
console.log('Array.isArray(properties)', Array.isArray(properties));
console.log(
'Object.prototype.toString.call(properties)',
Object.prototype.toString.call(properties)
);
console.log(
'expect.findTypeOf(properties).name',
expect.findTypeOf(properties).name
);
expect.withError(
() => {
Object.keys(properties).forEach(property => {
Expand Down
55 changes: 49 additions & 6 deletions lib/createTopLevelExpect.js
Expand Up @@ -1197,6 +1197,9 @@ expectPrototype.lookupAssertionRule = function(
'The expect function requires the second parameter to be a string or an expect.it.'
);
}
if (testDescriptionString === 'to have properties') {
console.log('here we are, testDescriptionString', testDescriptionString);
}
let handlers;
let instance = this;
while (instance) {
Expand All @@ -1222,8 +1225,9 @@ expectPrototype.lookupAssertionRule = function(
return type;
};

const matches = (value, assertionType, key, relaxed) => {
const matches = (value, assertionType, key, relaxed, debug) => {
if (assertionType.is('assertion') && typeof value === 'string') {
if (debug) console.log('matches disq #1');
return true;
}

Expand All @@ -1236,15 +1240,20 @@ expectPrototype.lookupAssertionRule = function(
}
return assertionType.identify(value);
} else {
return findTypeOf(value, key).is(assertionType);
const type = findTypeOf(value, key);
const is = type.is(assertionType);
if (debug) console.log('matches case #1 type', type, 'is', is);
return is;
}
};

function matchesHandler(handler, relaxed) {
function matchesHandler(handler, relaxed, debug) {
if (!matches(subject, handler.subject.type, 'subject', relaxed)) {
if (debug) console.log('disq because subject type mismatches');
return false;
}
if (requireAssertionSuffix && !handler.args.some(isAssertionArg)) {
if (debug) console.log('disq in case 2');
return false;
}

Expand All @@ -1254,25 +1263,59 @@ expectPrototype.lookupAssertionRule = function(
args.length < requireArgumentsLength.minimum ||
requireArgumentsLength.maximum < args.length
) {
if (debug) {
console.log(
'disq in case 3',
'args.length',
args.length,
'requireArgumentsLength.minimum',
requireArgumentsLength.minimum,
'requireArgumentsLength.maximum',
requireArgumentsLength.maximum
);
}
return false;
} else if (args.length === 0 && requireArgumentsLength.maximum === 0) {
if (debug) console.log('succeed in case 4');
return true;
}

const lastRequirement = handler.args[handler.args.length - 1];
return args.every((arg, i) => {
if (i < handler.args.length - 1) {
return matches(arg, handler.args[i].type, i, relaxed);
const result = matches(arg, handler.args[i].type, i, relaxed, debug);
if (debug) console.log('result #1 of matching arg', i, result);
return result;
} else {
return matches(arg, lastRequirement.type, i, relaxed);
const result = matches(arg, lastRequirement.type, i, relaxed, debug);
if (debug) console.log('result #2 of matching arg', i, result);
return result;
}
});
}

let j, handler;
for (j = 0; j < handlers.length; j += 1) {
handler = handlers[j];
if (matchesHandler(handler)) {
if (testDescriptionString === 'to have properties') {
console.log('checking handler', handler);
console.log('alternations', handler.alternations);
console.log('flags', handler.flags);
console.log('subject', handler.subject);
console.log('args', handler.args);
console.log('testDescriptionString', handler.testDescriptionString);
console.log('declaration', handler.declaration);
console.log('expect', handler.expect);
console.log('specificity', handler.specificity);
}

if (
matchesHandler(
handler,
undefined,
testDescriptionString === 'to have properties'
)
) {
return handler;
}
}
Expand Down

0 comments on commit 20824e4

Please sign in to comment.