Skip to content

Commit

Permalink
test: add mapTaggedTemplateLiteralInvocation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jun 5, 2017
1 parent ac03e5d commit edf6ae4
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions test/utilities/mapTaggedTemplateLiteralInvocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// @flow

import test from 'ava';
import sinon from 'sinon';
import {
sql
} from '../../src';
import {
mapTaggedTemplateLiteralInvocation
} from '../../src/utilities';

test('regular invocation', (t) => {
const spy = sinon.spy();

mapTaggedTemplateLiteralInvocation(spy)('foo');

t.true(spy.calledOnce);

t.true(spy.firstCall.args[0] === 'foo');
});

test('regular invocation with parameters', (t) => {
const spy = sinon.spy();

mapTaggedTemplateLiteralInvocation(spy)('foo', ['bar']);

t.true(spy.calledOnce);

t.true(spy.firstCall.args[0] === 'foo');
t.deepEqual(spy.firstCall.args[1], ['bar']);
});

test('sql tag invocation', (t) => {
const spy = sinon.spy();

mapTaggedTemplateLiteralInvocation(spy)(sql`foo`);

t.true(spy.calledOnce);

t.true(spy.firstCall.args[0] === 'foo');
t.deepEqual(spy.firstCall.args[1], []);
});

test('sql tag invocation with expressions', (t) => {
const spy = sinon.spy();

mapTaggedTemplateLiteralInvocation(spy)(sql`foo ${'bar'}`);

t.true(spy.calledOnce);

t.true(spy.firstCall.args[0] === 'foo ?');
t.deepEqual(spy.firstCall.args[1], ['bar']);
});

test('sql tag invocation with values', (t) => {
const spy = sinon.spy();

mapTaggedTemplateLiteralInvocation(spy)(sql`foo`, ['bar']);

t.true(spy.calledOnce);

t.true(spy.firstCall.args[0] === 'foo');
t.deepEqual(spy.firstCall.args[1], ['bar']);
});

test('sql tag invocation with expressions and values', (t) => {
const spy = sinon.spy();

mapTaggedTemplateLiteralInvocation(spy)(sql`foo ${'bar1'}`, ['bar2']);

t.true(spy.calledOnce);

t.true(spy.firstCall.args[0] === 'foo ?');
t.deepEqual(spy.firstCall.args[1], ['bar1', 'bar2']);
});

0 comments on commit edf6ae4

Please sign in to comment.