Updated test
This commit is contained in:
@ -10,10 +10,9 @@ import {
|
||||
|
||||
const client = new Client({ node: 'http://localhost:9200' })
|
||||
|
||||
client.on(events.REQUEST, (meta: EventMeta) => {})
|
||||
client.on(events.RESPONSE, (meta: EventMeta) => {})
|
||||
client.on(events.ERROR, (err: Error, meta: EventMeta) => {})
|
||||
client.on(events.SNIFF, (err: Error, meta: SniffMeta) => {})
|
||||
client.on(events.REQUEST, (err: Error | null, meta: EventMeta) => {})
|
||||
client.on(events.RESPONSE, (err: Error | null, meta: EventMeta) => {})
|
||||
client.on(events.SNIFF, (err: Error | null, meta: SniffMeta) => {})
|
||||
|
||||
// Callbacks
|
||||
client.info((err: Error | null, result: ApiResponse) => {})
|
||||
|
||||
@ -6,14 +6,15 @@ const { TimeoutError } = require('../../lib/errors')
|
||||
const { connection: { MockConnection, MockConnectionTimeout } } = require('../utils')
|
||||
|
||||
test('Should emit a request event when a request is performed', t => {
|
||||
t.plan(2)
|
||||
t.plan(3)
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: MockConnection
|
||||
})
|
||||
|
||||
client.on(events.REQUEST, meta => {
|
||||
client.on(events.REQUEST, (err, meta) => {
|
||||
t.error(err)
|
||||
t.match(meta, {
|
||||
connection: {
|
||||
id: 'http://localhost:9200'
|
||||
@ -39,14 +40,15 @@ test('Should emit a request event when a request is performed', t => {
|
||||
})
|
||||
|
||||
test('Should emit a response event in case of a successful response', t => {
|
||||
t.plan(2)
|
||||
t.plan(3)
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: MockConnection
|
||||
})
|
||||
|
||||
client.on(events.RESPONSE, meta => {
|
||||
client.on(events.RESPONSE, (err, meta) => {
|
||||
t.error(err)
|
||||
t.match(meta, {
|
||||
connection: {
|
||||
id: 'http://localhost:9200'
|
||||
@ -79,7 +81,7 @@ test('Should emit a response event in case of a successful response', t => {
|
||||
})
|
||||
})
|
||||
|
||||
test('Should emit an error event in case of a failing response', t => {
|
||||
test('Should emit a response event with the error set', t => {
|
||||
t.plan(3)
|
||||
|
||||
const client = new Client({
|
||||
@ -88,12 +90,8 @@ test('Should emit an error event in case of a failing response', t => {
|
||||
maxRetries: 0
|
||||
})
|
||||
|
||||
client.on(events.RESPONSE, ({ connection, request, response }) => {
|
||||
t.fail('This should not be called')
|
||||
})
|
||||
|
||||
client.on(events.ERROR, (error, meta) => {
|
||||
t.ok(error instanceof TimeoutError)
|
||||
client.on(events.RESPONSE, (err, meta) => {
|
||||
t.ok(err instanceof TimeoutError)
|
||||
t.match(meta, {
|
||||
connection: {
|
||||
id: 'http://localhost:9200'
|
||||
|
||||
Reference in New Issue
Block a user