forwardemail / forwardemail/supertest

Expect empty array or object is ignored when response is a string

Open
#443 0 comments 3 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
14.4k
Forks
782
PR merge metrics
No merged PRs in 30d

Description

`.expect(status, body)` seems to be working incorrectly when expecting empty array or object and response was plain text. The example below hopefully illustrates the issue.

```
const host = 'http://localhost:1234';

// Mock backend
const nock = require('nock');
nock(host)
.persist()
.get('/')
.reply(200, 'Hello world');

// Test mocked backend
const supertest = require('supertest');

const done = (err, result) => {
if(err) console.error(err)
else console.log('OK');
}

supertest(host)
.get('/')
.expect(200, '')
.end(done);

supertest(host)
.get('/')
.expect(200, [])
.end(done);
```

Gives me the following output:
```
Error: expected '' response body, got 'Hello world'
"OK"
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.