Skip to content

Commit

Permalink
test: add select subroutine tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jan 31, 2017
1 parent 84cb168 commit 4ec602c
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/surgeon/subroutines/selectSubroutine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import test from 'ava';
import sinon from 'sinon';
import selectSubroutine from '../../../src/subroutines/selectSubroutine';

test('returns array when expecting multiple results', (t): void => {
const isElement = sinon.stub().returns(true);
const querySelectorAll = sinon.stub().returns(['foo', 'bar']);

const results = selectSubroutine({
isElement,
querySelectorAll
}, null, ['.foo', '{0,}']);

t.deepEqual(results, ['foo', 'bar']);
});

test('returns a single result when expecting at most 1 result', (t): void => {
const isElement = sinon.stub().returns(true);
const querySelectorAll = sinon.stub().returns(['foo']);

const result = selectSubroutine({
isElement,
querySelectorAll
}, null, ['.foo', '{0,1}']);

t.true(result === 'foo');
});

test('returns an empty array when expecting multiple results', (t): void => {
const isElement = sinon.stub().returns(true);
const querySelectorAll = sinon.stub().returns([]);

const results = selectSubroutine({
isElement,
querySelectorAll
}, null, ['.foo', '{0,}']);

t.deepEqual(results, []);
});

test('returns null when expecting at most 1 result', (t): void => {
const isElement = sinon.stub().returns(true);
const querySelectorAll = sinon.stub().returns([]);

const result = selectSubroutine({
isElement,
querySelectorAll
}, null, ['.foo', '{0,1}']);

t.true(result === null);
});

0 comments on commit 4ec602c

Please sign in to comment.