Skip to content

Commit

Permalink
prettier --write '**/*.js'
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Nov 19, 2020
1 parent 101bd87 commit 0033de7
Show file tree
Hide file tree
Showing 8 changed files with 174 additions and 180 deletions.
10 changes: 5 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ const config = {
'import/no-unresolved': ['error', { commonjs: true }],
'mocha/no-exclusive-tests': 'error',
'mocha/no-nested-tests': 'error',
'mocha/no-identical-title': 'error'
'mocha/no-identical-title': 'error',
},
overrides: [
{
files: ['test/**/*.js'],
env: {
mocha: true
}
}
]
mocha: true,
},
},
],
};

module.exports = config;
64 changes: 29 additions & 35 deletions lib/unexpectedMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function getFunctionName(f) {

function retrieveMapValues(theMap) {
const values = [];
theMap.forEach(value => {
theMap.forEach((value) => {
values.push(value);
});
return values;
Expand All @@ -33,22 +33,16 @@ class MapValue {
}

function createUnexpectedMap(expect) {
expect.addStyle('propertyForMap', function(key, inspectedValue) {
this.text('[')
.appendInspected(key)
.text(',')
.sp()
.append(inspectedValue);
expect.addStyle('propertyForMap', function (key, inspectedValue) {
this.text('[').appendInspected(key).text(',').sp().append(inspectedValue);
});

expect.addStyle('propertyForMapInSatisfy', function(
expect.addStyle('propertyForMapInSatisfy', function (
key,
inspectedValue,
isValueDiff
) {
this.text('[')
.appendInspected(key)
.text(',');
this.text('[').appendInspected(key).text(',');
if (isValueDiff) {
this.nl().sp(2);
} else {
Expand Down Expand Up @@ -82,7 +76,7 @@ function createUnexpectedMap(expect) {
},
suffix(output) {
return output;
}
},
});

const objectType = expect.getType('object');
Expand Down Expand Up @@ -140,7 +134,7 @@ function createUnexpectedMap(expect) {
return output;
},
getKeys: Object.getOwnPropertySymbols
? function(obj) {
? function (obj) {
const keys = this.retrieveKeys(obj);
const symbols = Object.getOwnPropertySymbols(obj);
if (symbols.length > 0) {
Expand All @@ -149,7 +143,7 @@ function createUnexpectedMap(expect) {
return keys;
}
}
: function(obj) {
: function (obj) {
return this.retrieveKeys(obj);
},
hasKey(obj, key) {
Expand All @@ -165,7 +159,7 @@ function createUnexpectedMap(expect) {
uniqueKeys(subjectKeys, valueKeys) {
const subjectKeysSet = new Set(subjectKeys);
const uniqueValueKeys = valueKeys.filter(
valueKey => !subjectKeysSet.has(valueKey)
(valueKey) => !subjectKeysSet.has(valueKey)
);

const uniqueKeys = [...subjectKeys, ...uniqueValueKeys];
Expand All @@ -174,7 +168,7 @@ function createUnexpectedMap(expect) {
},
valueForKey(obj, key) {
return new MapValue(obj.get(key));
}
},
});

expect.addAssertion('<Map> [not] to be empty', (expect, subject) => {
Expand All @@ -190,20 +184,20 @@ function createUnexpectedMap(expect) {
() => {
expect(expect.equal(value, subject), 'to be truthy');
},
e => {
(e) => {
expect.fail({
label: 'should equal',
diff(output, diff) {
return diff(subject, value);
}
},
});
}
);
});

expect.addAssertion('<Map> to equal <any>', (expect, actual, expected) => {
expect.fail({
diff: output => {
diff: (output) => {
return output
.text('Mismatching constructors ')
.text(
Expand All @@ -215,7 +209,7 @@ function createUnexpectedMap(expect) {
(expected.constructor && getFunctionName(expected.constructor)) ||
expected.constructor
);
}
},
});
});

Expand Down Expand Up @@ -256,17 +250,17 @@ function createUnexpectedMap(expect) {
.all([
expect.promise(() => {
if (expect.flags.exhaustively) {
const nonOwnKeysWithDefinedValues = keys.filter(key => {
const nonOwnKeysWithDefinedValues = keys.filter((key) => {
return (
!Object.prototype.hasOwnProperty.call(subject, key) &&
typeof subject[key] !== 'undefined'
);
});
const valueKeysWithDefinedValues = keys.filter(key => {
const valueKeysWithDefinedValues = keys.filter((key) => {
const valueKey = value.get(key);
return typeof valueKey !== 'undefined';
});
const subjectKeysWithDefinedValues = subjectKeys.filter(key => {
const subjectKeysWithDefinedValues = subjectKeys.filter((key) => {
const subjectKey = subject.get(key);
return typeof subjectKey !== 'undefined';
});
Expand All @@ -278,7 +272,7 @@ function createUnexpectedMap(expect) {
);
}
}),
expect.promise.all(promisesInFlight)
expect.promise.all(promisesInFlight),
])
.caught(() => {
return expect.promise.settle(promisesInFlight).then(() => {
Expand All @@ -288,7 +282,7 @@ function createUnexpectedMap(expect) {
const valueKeys = valueType.getKeys(value);
const uniqueKeys = subjectType
.uniqueKeys(subjectKeys, valueKeys)
.filter(key => {
.filter((key) => {
const valueKey = value.get(key);
const subjectHasKey = subject.has(key);
// Skip missing keys expected to be missing so they don't get rendered in the diff
Expand All @@ -310,7 +304,7 @@ function createUnexpectedMap(expect) {
output
.nl(index > 0 ? 1 : 0)
.i()
.block(function() {
.block(function () {
let valueOutput;
const annotation = output.clone();
let conflicting;
Expand Down Expand Up @@ -416,7 +410,7 @@ function createUnexpectedMap(expect) {
valueOutput.sp();
}

valueOutput.annotationBlock(function() {
valueOutput.annotationBlock(function () {
this.append(annotation);
});
}
Expand All @@ -435,7 +429,7 @@ function createUnexpectedMap(expect) {

if (isExhaustiveValueDiff) {
output
.annotationBlock(function() {
.annotationBlock(function () {
this.append(annotation);
})
.text(':')
Expand All @@ -454,7 +448,7 @@ function createUnexpectedMap(expect) {
return output
.nl(suffixOutput.isEmpty() ? 0 : 1)
.append(suffixOutput);
}
},
});
});
});
Expand All @@ -464,7 +458,7 @@ function createUnexpectedMap(expect) {
expect.addAssertion(
[
'<Map> to have values [exhaustively] satisfying <any>',
'<Map> to have values [exhaustively] satisfying <assertion>'
'<Map> to have values [exhaustively] satisfying <assertion>',
],
(expect, subject, nextArg) => {
expect.errorMode = 'nested';
Expand All @@ -473,11 +467,11 @@ function createUnexpectedMap(expect) {

const expected = new Map();
const keys = expect.subjectType.getKeys(subject);
keys.forEach(key => {
keys.forEach((key) => {
if (typeof nextArg === 'string') {
expected.set(
key,
expect.it(s => expect.shift(s))
expect.it((s) => expect.shift(s))
);
} else {
expected.set(key, nextArg);
Expand All @@ -488,7 +482,7 @@ function createUnexpectedMap(expect) {
() => {
return expect(subject, 'to [exhaustively] satisfy', expected);
},
err => {
(err) => {
expect.fail({
message(output) {
output.append(
Expand All @@ -499,7 +493,7 @@ function createUnexpectedMap(expect) {
const diff = err.getDiff({ output });
diff.inline = true;
return diff;
}
},
});
}
);
Expand All @@ -516,5 +510,5 @@ function createUnexpectedMap(expect) {

module.exports = {
name: 'unexpected-map',
installInto: createUnexpectedMap
installInto: createUnexpectedMap,
};
4 changes: 2 additions & 2 deletions test/assertions/Map.to-be-empty.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('to be empty assertion', () => {
new Map([
[1, 'foo'],
[2, 'bar'],
[3, 'baz']
[3, 'baz'],
]),
'not to be empty'
);
Expand All @@ -22,7 +22,7 @@ describe('to be empty assertion', () => {
new Map([
[1, 'foo'],
[2, 'bar'],
[3, 'baz']
[3, 'baz'],
]),
'to be empty'
);
Expand Down
8 changes: 4 additions & 4 deletions test/assertions/Map.to-equal.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* global expect */
describe('to equal assertion', function() {
describe('to equal assertion', function () {
it('should show two maps being equal', () => {
expect(function() {
expect(function () {
expect(new Map([['foo', 123]]), 'to equal', new Map([['foo', 123]]));
}, 'not to throw');
});

it('should show two maps not being equal (subject)', () => {
expect(
function() {
function () {
expect(new Map([[{}, 123]]), 'to equal', new Map([[{}, 123]]));
},
'to throw an error satisfying',
Expand All @@ -26,7 +26,7 @@ describe('to equal assertion', function() {

it('should show two maps not being equal (value)', () => {
expect(
function() {
function () {
expect(new Map([[123, {}]]), 'to equal', new Map([[123, {}]]));
},
'to throw an error satisfying',
Expand Down
26 changes: 13 additions & 13 deletions test/assertions/Map.to-have-values-satisfying.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* global expect */
describe('to have values satisfying assertion', function() {
it('should pass with an assertion', function() {
expect(function() {
describe('to have values satisfying assertion', function () {
it('should pass with an assertion', function () {
expect(function () {
expect(new Map([[[], null]]), 'to have values satisfying', 'to be null');
}, 'not to error');
});

it('should pass with an expect.it', function() {
expect(function() {
it('should pass with an expect.it', function () {
expect(function () {
expect(
new Map([[[], null]]),
'to have values satisfying',
Expand All @@ -16,21 +16,21 @@ describe('to have values satisfying assertion', function() {
}, 'not to error');
});

it('should pass with an object value and satisfy semantics', function() {
expect(function() {
it('should pass with an object value and satisfy semantics', function () {
expect(function () {
expect(new Map([[[], { foo: null }]]), 'to have values satisfying', {
foo: expect.it('to be falsy')
foo: expect.it('to be falsy'),
});
}, 'not to error');
});

it('fails if the given Map is empty', () => {
expect(
function() {
function () {
expect(
new Map(),
'to have values satisfying',
expect.it(value => {
expect.it((value) => {
expect(value, 'to equal', '0');
})
);
Expand All @@ -47,11 +47,11 @@ describe('to have values satisfying assertion', function() {
);
});

it('should render a diff when failing "to have values satisfying"', function() {
it('should render a diff when failing "to have values satisfying"', function () {
expect(
function() {
function () {
expect(new Map([[[], { foo: null }]]), 'to have values satisfying', {
foo: expect.it('to be a number')
foo: expect.it('to be a number'),
});
},
'to throw an error satisfying',
Expand Down
Loading

0 comments on commit 0033de7

Please sign in to comment.