Skip to content

Commit

Permalink
Add it.skip function
Browse files Browse the repository at this point in the history
  • Loading branch information
mattphillips committed Mar 28, 2017
1 parent dc93586 commit 1a17f20
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default (parameterRows, defaultGlobal = global) => {

const it = parameterisedTests(parameterRows, globalIt);
it.skip = parameterisedTests(parameterRows, globalIt.skip);
it.only = parameterisedTests(parameterRows, globalIt.only);

return { test, it };
};
Expand Down
65 changes: 65 additions & 0 deletions src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,69 @@ describe('jest-each', () => {
expect(typeof globalItSkipMock.it.skip.mock.calls[0][1] === 'function').toBe(true);
});
});

describe('.it.only', () => {
test('calls global it only with given title', () => {
const globalItOnlyMock = { it: { only: jest.fn() }, test: {} };
each([[]], globalItOnlyMock).it.only('expected string', () => {});

expect(globalItOnlyMock.it.only.mock.calls.length).toBe(1);
expect(globalItOnlyMock.it.only.mock.calls[0][0]).toBe('expected string');
});

test('calls global it only with given title when multiple tests cases exist', () => {
const globalItOnlyMock = { it: { only: jest.fn() }, test: {} };
each([[], []], globalItOnlyMock).it.only('expected string', () => {});

expect(globalItOnlyMock.it.only.mock.calls.length).toBe(2);
expect(globalItOnlyMock.it.only.mock.calls[0][0]).toBe('expected string');
});

test('calls global it only with title containing param values when using sprintf format', () => {
const globalItOnlyMock = { it: { only: jest.fn() }, test: {} };
each([['hello', 1], ['world', 2]], globalItOnlyMock).it.only('expected string: %s %s', () => {});

expect(globalItOnlyMock.it.only.mock.calls.length).toBe(2);
expect(globalItOnlyMock.it.only.mock.calls[0][0]).toBe('expected string: hello 1');
expect(globalItOnlyMock.it.only.mock.calls[1][0]).toBe('expected string: world 2');
});

test('calls global it only with cb function', () => {
const globalItOnlyMock = { it: { only: jest.fn() }, test: {} };
const testCallBack = jest.fn();
each([[]], globalItOnlyMock).it.only('expected string', testCallBack);

expect(globalItOnlyMock.it.only.mock.calls.length).toBe(1);
expect(typeof globalItOnlyMock.it.only.mock.calls[0][1] === 'function').toBe(true);
});

test('calls global it only with cb function containing all parameters of first row when multiple test cases exist', () => {
const globalItOnlyMock = { it: { only: jest.fn() }, test: {} };
const testCallBack = jest.fn();
each([
['hello', 'world'],
['joe', 'bloggs'],
], globalItOnlyMock).it.only('expected string', testCallBack);

globalItOnlyMock.it.only.mock.calls[0][1]();
expect(testCallBack.mock.calls.length).toBe(1);
expect(testCallBack.mock.calls[0][0]).toBe('hello');
expect(testCallBack.mock.calls[0][1]).toBe('world');

globalItOnlyMock.it.only.mock.calls[1][1]();
expect(testCallBack.mock.calls.length).toBe(2);
expect(testCallBack.mock.calls[1][0]).toBe('joe');
expect(testCallBack.mock.calls[1][1]).toBe('bloggs');
});

test('calls global it only with async done when cb function has more args than params of given test row', () => {
const globalItOnlyMock = { it: { only: jest.fn() }, test: {} };
each([['hello']], globalItOnlyMock).it.only('expected string', (hello, done) => {
expect(hello).toBe('hello');
expect(done).toBe('DONE');
});

globalItOnlyMock.it.only.mock.calls[0][1]('DONE');
});
});
});

0 comments on commit 1a17f20

Please sign in to comment.