Skip to content

Commit

Permalink
refactor(test): Chai assert basic auth & body match (#1952)
Browse files Browse the repository at this point in the history
Also migrated a couple tests from request > got.
  • Loading branch information
mastermatt committed Mar 16, 2020
1 parent bcdb4d0 commit 92575b6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 95 deletions.
18 changes: 10 additions & 8 deletions tests/test_basic_auth.js
@@ -1,11 +1,13 @@
'use strict'

const { expect } = require('chai')
const { test } = require('tap')
const assertRejects = require('assert-rejects')
const nock = require('..')
const got = require('./got_client')

require('./cleanup_after_each')()
require('./setup')

test('basic auth with username and password', async t => {
t.beforeEach(done => {
Expand All @@ -16,16 +18,16 @@ test('basic auth with username and password', async t => {
done()
})

await t.test('succeeds when it matches', async tt => {
await t.test('succeeds when it matches', async () => {
const response = await got('http://example.test/test', {
username: 'foo',
password: 'bar',
})
tt.equal(response.statusCode, 200)
tt.equal(response.body, 'Here is the content')
expect(response.statusCode).to.equal(200)
expect(response.body).to.equal('Here is the content')
})

await t.test('fails when it doesnt match', async tt => {
await t.test('fails when it doesnt match', async () => {
await assertRejects(
got('http://example.test/test'),
/Nock: No match for request/
Expand All @@ -42,16 +44,16 @@ test('basic auth with username only', async t => {
done()
})

await t.test('succeeds when it matches', async tt => {
await t.test('succeeds when it matches', async () => {
const response = await got('http://example.test/test', {
username: 'foo',
password: '',
})
tt.equal(response.statusCode, 200)
tt.equal(response.body, 'Here is the content')
expect(response.statusCode).to.equal(200)
expect(response.body).to.equal('Here is the content')
})

await t.test('fails when it doesnt match', async tt => {
await t.test('fails when it doesnt match', async () => {
await assertRejects(
got('http://example.test/test'),
/Nock: No match for request/
Expand Down

0 comments on commit 92575b6

Please sign in to comment.