Files
elasticsearch-js/test/unit/serializer.test.js
delvedor b6b04f99d8 WIP: Added some basic unit tests
- Added unit test
- Added test fixtures
- Added test utils
2018-10-22 16:54:14 +02:00

40 lines
871 B
JavaScript

'use strict'
const { test } = require('tap')
const Serializer = require('../../lib/Serializer')
const { SerializationError, DeserializationError } = require('../../lib/errors')
test('Basic', t => {
t.plan(2)
const s = new Serializer()
const obj = { hello: 'world' }
const json = JSON.stringify(obj)
t.strictEqual(s.serialize(obj), json)
t.deepEqual(s.deserialize(json), obj)
})
test('SerializationError', t => {
t.plan(1)
const s = new Serializer()
const obj = { hello: 'world' }
obj.o = obj
try {
s.serialize(obj)
t.fail('Should fail')
} catch (err) {
t.ok(err instanceof SerializationError)
}
})
test('DeserializationError', t => {
t.plan(1)
const s = new Serializer()
const json = '{"hello'
try {
s.deserialize(json)
t.fail('Should fail')
} catch (err) {
t.ok(err instanceof DeserializationError)
}
})