-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add mapTaggedTemplateLiteralInvocation tests
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
}); |