Skip to content

Commit

Permalink
Reformat all files with prettier 2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Dec 16, 2020
1 parent 2c35d0c commit 55268ea
Show file tree
Hide file tree
Showing 30 changed files with 916 additions and 937 deletions.
151 changes: 75 additions & 76 deletions documentation/api/UnexpectedError.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,42 +27,42 @@ output.appendErrorMessage(error);
This is useful if you want to combine multiple errors in one assertion:

```js
expect.addAssertion('<array> to have item satisfying <any+>', function (
expect,
subject
) {
const args = Array.prototype.slice.call(arguments, 2);
const promises = subject.map(function (item) {
return expect.promise(function () {
return expect.apply(expect, [item].concat(args));
});
});

return expect.promise.settle(promises).then(function () {
const failed = promises.every(function (promise) {
return promise.isRejected();
expect.addAssertion(
'<array> to have item satisfying <any+>',
function (expect, subject) {
const args = Array.prototype.slice.call(arguments, 2);
const promises = subject.map(function (item) {
return expect.promise(function () {
return expect.apply(expect, [item].concat(args));
});
});

if (failed) {
expect.fail({
diff: function (output, diff, inspect, equal) {
output.inline = true;
promises.forEach(function (promise, index) {
if (index > 0) {
output.nl(2);
}
const error = promise.reason();
// the error is connected to the current scope
// but we are just interested in the nested error
error.errorMode = 'bubble';
output.append(error.getErrorMessage(output));
});
return output;
},
return expect.promise.settle(promises).then(function () {
const failed = promises.every(function (promise) {
return promise.isRejected();
});
}
});
});

if (failed) {
expect.fail({
diff: function (output, diff, inspect, equal) {
output.inline = true;
promises.forEach(function (promise, index) {
if (index > 0) {
output.nl(2);
}
const error = promise.reason();
// the error is connected to the current scope
// but we are just interested in the nested error
error.errorMode = 'bubble';
output.append(error.getErrorMessage(output));
});
return output;
},
});
}
});
}
);
```

When the assertion fails we get the following output:
Expand Down Expand Up @@ -99,24 +99,23 @@ We could for example change the error mode for all the errors in the
chain to `nested`:

```js
expect.addAssertion('<any> detailed to be <any>', function (
expect,
subject,
value
) {
expect.errorMode = 'bubble';
expect.withError(
function () {
expect(subject, 'to be', value);
},
function (err) {
err.getParents().forEach(function (e) {
e.errorMode = 'nested';
});
expect.fail(err);
}
);
});
expect.addAssertion(
'<any> detailed to be <any>',
function (expect, subject, value) {
expect.errorMode = 'bubble';
expect.withError(
function () {
expect(subject, 'to be', value);
},
function (err) {
err.getParents().forEach(function (e) {
e.errorMode = 'nested';
});
expect.fail(err);
}
);
}
);

expect('f00!', 'detailed to be', 'foo!');
```
Expand Down Expand Up @@ -159,31 +158,31 @@ create the diff. Now you can delegate to that method from
`expect.fail`:

```js
expect.addAssertion('<any> to be completely custom', function (
expect,
subject
) {
return expect.withError(
function () {
expect(subject, 'to satisfy', { custom: true });
},
function (err) {
const createDiff = err.getDiffMethod();
expect.fail({
diff: function (output, diff, inspect, equal) {
output
.text('~~~~~~~~~~~~~~')
.sp()
.success('custom')
.sp()
.text('~~~~~~~~~~~~~~')
.nl();
return createDiff(output, diff, inspect, equal);
},
});
}
);
});
expect.addAssertion(
'<any> to be completely custom',
function (expect, subject) {
return expect.withError(
function () {
expect(subject, 'to satisfy', { custom: true });
},
function (err) {
const createDiff = err.getDiffMethod();
expect.fail({
diff: function (output, diff, inspect, equal) {
output
.text('~~~~~~~~~~~~~~')
.sp()
.success('custom')
.sp()
.text('~~~~~~~~~~~~~~')
.nl();
return createDiff(output, diff, inspect, equal);
},
});
}
);
}
);

expect({ custom: false }, 'to be completely custom');
```
Expand Down
Loading

0 comments on commit 55268ea

Please sign in to comment.