Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show that we can use modern syntax in the documentation #507

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 16 additions & 32 deletions documentation/assertions/function/to-throw.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ You can assert the error message is a given string if you provide a
string as the second parameter.

```js
expect(
function() {
throw new Error('The error message');
},
'to throw',
'The error message'
);
expect(() => {
throw new Error('The error message');
}, 'to throw', 'The error message');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I find arrow-funcs spanning several lines can be quite difficult to read. I generally tend towards:

expect(
  () => { throw new Error("The error message"); },
  "to throw", "The error message"
);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should aim at formatting te documentation with prettier. So whatever it decides.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says:

expect(
  () => {
    throw new Error('The error message');
  },
  'to throw',
  'The error message'
);

```

In case of a failing expectation you get the following output:

```js
expect(function () {
expect(() => {
throw new Error('The error message!');
}, 'to throw', 'The error message');
```
Expand All @@ -57,19 +53,14 @@ By providing a regular expression as the second parameter you can
assert the error message matches the given regular expression.

```js
expect(
function() {
throw new Error('The error message');
},
'to throw',
/error message/
);
expect(() => {
throw new Error('The error message');
}, 'to throw', /error message/);
```

In case of a failing expectation you get the following output:

```js
expect(function () {
expect(() => {
throw new Error('The error message!');
}, 'to throw', /catastrophic failure/);
```
Expand All @@ -86,13 +77,9 @@ to throw /catastrophic failure/
That can also just supply an error object to validate against:

```js
expect(
function() {
throw new TypeError('Invalid syntax');
},
'to throw',
new TypeError('Invalid syntax')
);
expect(() => {
throw new TypeError('Invalid syntax');
}, 'to throw', new TypeError('Invalid syntax'));
```

In case of a failing expectation you get the following output:
Expand All @@ -113,7 +100,7 @@ to throw TypeError('Invalid syntax')
```

```js
expect(function() {
expect(() => {
// Do some work that should not throw
}, 'not to throw');
```
Expand Down Expand Up @@ -142,11 +129,8 @@ function willThrow(input) {
if (input) throw new SyntaxError('The error message');
return input;
}
expect(
function() {
willThrow('input.here');
},
'to throw',
new SyntaxError('The error message')
);

expect(() => {
willThrow('input.here');
}, 'to throw', new SyntaxError('The error message'));
```