Avoid the release of Zalgo (#1295)
This commit is contained in:
committed by
GitHub
parent
96a54d0539
commit
7f317d3321
@ -314,6 +314,22 @@ test('ConfigurationError (promises)', t => {
|
||||
})
|
||||
})
|
||||
|
||||
test('The callback with a sync error should be called in the next tick', t => {
|
||||
t.plan(4)
|
||||
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200'
|
||||
})
|
||||
|
||||
const transportReturn = client.index({ body: { foo: 'bar' } }, (err, result) => {
|
||||
t.ok(err instanceof errors.ConfigurationError)
|
||||
})
|
||||
|
||||
t.type(transportReturn.then, 'function')
|
||||
t.type(transportReturn.catch, 'function')
|
||||
t.type(transportReturn.abort, 'function')
|
||||
})
|
||||
|
||||
if (Number(process.version.split('.')[0].slice(1)) >= 8) {
|
||||
require('./api-async')(test)
|
||||
}
|
||||
|
||||
@ -2552,3 +2552,65 @@ test('Lowercase headers utilty', t => {
|
||||
|
||||
t.strictEqual(lowerCaseHeaders(undefined), undefined)
|
||||
})
|
||||
|
||||
test('The callback with a sync error should be called in the next tick - json', t => {
|
||||
t.plan(4)
|
||||
const pool = new ConnectionPool({ Connection })
|
||||
pool.addConnection('http://localhost:9200')
|
||||
|
||||
const transport = new Transport({
|
||||
emit: () => {},
|
||||
connectionPool: pool,
|
||||
serializer: new Serializer(),
|
||||
maxRetries: 3,
|
||||
requestTimeout: 30000,
|
||||
sniffInterval: false,
|
||||
sniffOnStart: false
|
||||
})
|
||||
|
||||
const body = { a: true }
|
||||
body.o = body
|
||||
|
||||
const transportReturn = transport.request({
|
||||
method: 'POST',
|
||||
path: '/hello',
|
||||
body
|
||||
}, (err, { body }) => {
|
||||
t.ok(err instanceof SerializationError)
|
||||
})
|
||||
|
||||
t.type(transportReturn.then, 'function')
|
||||
t.type(transportReturn.catch, 'function')
|
||||
t.type(transportReturn.abort, 'function')
|
||||
})
|
||||
|
||||
test('The callback with a sync error should be called in the next tick - ndjson', t => {
|
||||
t.plan(4)
|
||||
const pool = new ConnectionPool({ Connection })
|
||||
pool.addConnection('http://localhost:9200')
|
||||
|
||||
const transport = new Transport({
|
||||
emit: () => {},
|
||||
connectionPool: pool,
|
||||
serializer: new Serializer(),
|
||||
maxRetries: 3,
|
||||
requestTimeout: 30000,
|
||||
sniffInterval: false,
|
||||
sniffOnStart: false
|
||||
})
|
||||
|
||||
const field = { a: true }
|
||||
field.o = field
|
||||
|
||||
const transportReturn = transport.request({
|
||||
method: 'POST',
|
||||
path: '/hello',
|
||||
bulkBody: [field]
|
||||
}, (err, { body }) => {
|
||||
t.ok(err instanceof SerializationError)
|
||||
})
|
||||
|
||||
t.type(transportReturn.then, 'function')
|
||||
t.type(transportReturn.catch, 'function')
|
||||
t.type(transportReturn.abort, 'function')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user