Skip to content

Commit

Permalink
docs: update wording on usage (#339)
Browse files Browse the repository at this point in the history
Updates the usage to make it clear you can now import `request` rather
than using `chai.request`.
  • Loading branch information
43081j committed Sep 2, 2024
1 parent aa205ee commit 9b4f656
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ This is an addon plugin for the [Chai Assertion Library](https://www.chaijs.com/
Use this plugin as you would all other Chai plugins.

```js
import chaiModule from "chai";
import * as chai from "chai";
import chaiHttp from "chai-http";

const chai = chaiModule.use(chaiHttp);
chai.use(chaiHttp);

// if you need to access `request`
import {default as chaiHttp, request} from "chai-http";
chai.use(chaiHttp);
request.get(...).send(...);
```

To use Chai HTTP on a web page, please use the latest v4 version for now.
Expand Down Expand Up @@ -89,7 +94,7 @@ Once a request is created with a given VERB (get, post, etc), you chain on these
| `.set(key, value)` | Set request headers |
| `.send(data)` | Set request data (default type is JSON) |
| `.type(dataType)` | Change the type of the data sent from the `.send()` method (xml, form, etc) |
| `.attach(field, file, attachment)` | Attach a file |
| `.attach(field, file, attachment)` | Attach a file |
| `.auth(username, password)` | Add auth headers for Basic Authentication |
| `.query(parmasObject)` | Chain on some GET parameters |

Expand Down Expand Up @@ -139,12 +144,12 @@ chai.request.execute(app)
chai.request.execute(app)
.get('/protected')
.auth('user', 'pass')

// Authenticate with Bearer Token
chai.request.execute(app)
.get('/protected')
.auth(accessToken, { type: 'bearer' })
.auth(accessToken, { type: 'bearer' })

```

`.query()`
Expand Down

0 comments on commit 9b4f656

Please sign in to comment.