# Running Assertions

Frisby has many ways of running assertions against the HTTP response. Below are the following methods available by default:

## expect(*handler, \[...args]*)

Frisby comes with many handy built-in expect handlers to help you test the HTTP response of your API.

* `status` - Check HTTP status
* `header` - Check HTTP header key + value
* `json` - Match json structure + values
* `jsonStrict` - Match EXACT json structure + values (extra keys not tested for cause test failures)
* `jsonTypes` - Match json structure + value types
* `jsonTypesStrict` - Match EXACT json structure + value types (extra keys not tested for cause test failures)
* `bodyContains` - Match partial body content (string or regex)

### expect('status', statusCode)

```javascript
it('should be a teapot', function () {
  return frisby.get('https://httpbin.org/status/418')
    .expect('status', 418);
});
```

### expect('header', key \[, value])

```javascript
it('should have a JSON Content-Type header', function () {
  return frisby.get('https://httpbin.org/headers')
    .expect('header', 'Content-Type', 'application/json');
});
```

### expect('json' *\[, path]*, data)

```javascript
it('should have a "Host" header with a value of "httpbin.org"', function () {
  return frisby.get('https://httpbin.org/headers')
    .expect('json', 'headers', {
      Host: 'httpbin.org'
    });
});
```

A more complex example:

```javascript
it ('should return a list of feed items', function () {
  return frisby
    .get('https://jsonfeed.org/feed.json')
    .expect('status', 200)
    .expect('json', 'version', 'https://jsonfeed.org/version/1')
    .expect('json', 'title', 'JSON Feed')
    .expect('jsonTypes', 'items.*', { // Assert *each* object in 'items' array
      'id': Joi.string().required(),
      'url': Joi.string().uri().required(),
      'title': Joi.string().required(),
      'date_published': Joi.date().iso().required(),
    });
});
```

### expect('jsonTypes' *\[, path]*, data)

```javascript
it('should return all headers as strings', function () {
  return frisby.get('https://httpbin.org/headers')
    // Using a wildcard in the path '*' check EACH value
    .expect('jsonTypes', 'headers.*', frisby.Joi.string());
});
```

## expectNot(*handler, \[...args]*)

Runs an inverse assertion that passes when there is an error thrown. Uses all the same types and arguments as `expect()`.

```javascript
it('should not return an error', function () {
  return frisby.get('https://httpbin.org/headers')
    // Should not return an error
    .expectNot('json', { result: 'error' });
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.frisbyjs.com/api-and-usage/expectations-assertions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
