Skip to content

Commit

Permalink
Add test case to disable the value formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Herrmann committed Jun 25, 2019
1 parent 826edeb commit 0a30f42
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/sql.valueFormatter.js
Expand Up @@ -4,8 +4,10 @@ const sinon = require('sinon')
const sql = require('../')

describe('sql.valueFormatter', () => {
const originalValueFormatter = sql.valueFormatter
beforeEach(() => {
sql.client = undefined
sql.valueFormatter = originalValueFormatter
})

it('return object values as stringified JSON with default value formatter', () => {
Expand Down Expand Up @@ -50,4 +52,17 @@ describe('sql.valueFormatter', () => {
}
assert.deepEqual({ text: actualArg5.text, parameters: actualArg5.parameters }, expectedArg5)
})

it('return object values as they are given by overwriting the default value formatter', () => {
const object = { key: 'value' }

sql.valueFormatter = undefined
const actual = sql`INSERT INTO "table" (json) VALUES (${object})`

const expected = {
text: 'INSERT INTO "table" (json) VALUES ($1)',
parameters: [{ key: 'value' }]
}
assert.deepEqual({ text: actual.text, parameters: actual.parameters }, expected)
})
})

0 comments on commit 0a30f42

Please sign in to comment.