Skip to content

Commit

Permalink
Add tagged template literal each logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mattphillips committed May 1, 2018
1 parent fbb5572 commit 36952c5
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`installEach .describe Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1,1,1,1"
`;

exports[`installEach .describe Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1"
`;

exports[`installEach .fdescribe Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1,1,1,1"
`;

exports[`installEach .fdescribe Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1"
`;

exports[`installEach .fit Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1,1,1,1"
`;

exports[`installEach .fit Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1"
`;

exports[`installEach .it Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1,1,1,1"
`;

exports[`installEach .it Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1"
`;

exports[`installEach .xdescribe Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1,1,1,1"
`;

exports[`installEach .xdescribe Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1"
`;

exports[`installEach .xit Table Tagged Template Literal throws error when there are fewer arguments than headings over multiple rows 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1,1,1,1"
`;

exports[`installEach .xit Table Tagged Template Literal throws error when there are fewer arguments than headings when given one row 1`] = `
"Tagged Template Literal test error:
Not enough arguments supplied for given headings: a | b | expected
Received: 0,1"
`;
288 changes: 217 additions & 71 deletions packages/jest-jasmine2/src/__tests__/each.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,94 +26,240 @@ describe('installEach', () => {
};
};

test('calls global function with given title', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);
describe('Table Array', () => {
test('calls global function with given title', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];
const globalMock = environmentMock.global[keyPath];

globalMock.each([[]])('expected string', noop);
globalMock.each([[]])('expected string', noop);

expect(globalMock).toHaveBeenCalledTimes(1);
expect(globalMock).toHaveBeenCalledWith(
'expected string',
expectFunction,
);
});
expect(globalMock).toHaveBeenCalledTimes(1);
expect(globalMock).toHaveBeenCalledWith(
'expected string',
expectFunction,
);
});

test('calls global function with given title when multiple tests cases exist', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);
test('calls global function with given title when multiple tests cases exist', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];
const globalMock = environmentMock.global[keyPath];

globalMock.each([[], []])('expected string', noop);
globalMock.each([[], []])('expected string', noop);

expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
'expected string',
expectFunction,
);
expect(globalMock).toHaveBeenCalledWith(
'expected string',
expectFunction,
);
});
expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
'expected string',
expectFunction,
);
expect(globalMock).toHaveBeenCalledWith(
'expected string',
expectFunction,
);
});

test('calls global function with title containing param values when using sprintf format', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];

globalMock.each([['hello', 1], ['world', 2]])(
'expected string: %s %s',
noop,
);

expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
'expected string: hello 1',
expectFunction,
);
expect(globalMock).toHaveBeenCalledWith(
'expected string: world 2',
expectFunction,
);
});
test('calls global function with title containing param values when using sprintf format', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];

test('calls global function with cb function containing all parameters of each test case', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);
globalMock.each([['hello', 1], ['world', 2]])(
'expected string: %s %s',
noop,
);

const globalMock = environmentMock.global[keyPath];
const testCallBack = jest.fn();
globalMock.each([['hello', 'world'], ['joe', 'bloggs']])(
'expected string: %s %s',
testCallBack,
);
expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
'expected string: hello 1',
expectFunction,
);
expect(globalMock).toHaveBeenCalledWith(
'expected string: world 2',
expectFunction,
);
});

test('calls global function with cb function containing all parameters of each test case', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];
const testCallBack = jest.fn();
globalMock.each([['hello', 'world'], ['joe', 'bloggs']])(
'expected string: %s %s',
testCallBack,
);

globalMock.mock.calls[0][1]();
expect(testCallBack).toHaveBeenCalledTimes(1);
expect(testCallBack).toHaveBeenCalledWith('hello', 'world');

globalMock.mock.calls[1][1]();
expect(testCallBack).toHaveBeenCalledTimes(2);
expect(testCallBack).toHaveBeenCalledWith('joe', 'bloggs');
});

globalMock.mock.calls[0][1]();
expect(testCallBack).toHaveBeenCalledTimes(1);
expect(testCallBack).toHaveBeenCalledWith('hello', 'world');
test('calls global function with async done when cb function has more args than params of given test row', () => {
expect.hasAssertions();
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

globalMock.mock.calls[1][1]();
expect(testCallBack).toHaveBeenCalledTimes(2);
expect(testCallBack).toHaveBeenCalledWith('joe', 'bloggs');
const globalMock = environmentMock.global[keyPath];
globalMock.each([['hello']])('a title', (hello, done) => {
expect(hello).toBe('hello');
expect(done).toBe('DONE');
});

globalMock.mock.calls[0][1]('DONE');
});
});

test('calls global function with async done when cb function has more args than params of given test row', () => {
expect.hasAssertions();
const environmentMock = getEnvironmentMock();
installEach(environmentMock);
describe('Table Tagged Template Literal', () => {
test('throws error when there are fewer arguments than headings when given one row', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];
const testCallBack = jest.fn();

const globalMock = environmentMock.global[keyPath];
globalMock.each([['hello']])('a title', (hello, done) => {
expect(hello).toBe('hello');
expect(done).toBe('DONE');
globalMock.each`
a | b | expected
${0} | ${1} |
`('this will blow up :(', testCallBack);

expect(() =>
globalMock.mock.calls[0][1](),
).toThrowErrorMatchingSnapshot();
expect(testCallBack).not.toHaveBeenCalled();
});

globalMock.mock.calls[0][1]('DONE');
test('throws error when there are fewer arguments than headings over multiple rows', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];
const testCallBack = jest.fn();

globalMock.each`
a | b | expected
${0} | ${1} | ${1}
${1} | ${1} |
`('this will blow up :(', testCallBack);

expect(() =>
globalMock.mock.calls[0][1](),
).toThrowErrorMatchingSnapshot();
expect(testCallBack).not.toHaveBeenCalled();
});

test('calls global function with given title', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];

globalMock.each`
a | b | expected
${0} | ${1} | ${1}
`('expected string', noop);

expect(globalMock).toHaveBeenCalledTimes(1);
expect(globalMock).toHaveBeenCalledWith(
'expected string',
expectFunction,
);
});

test('calls global function with given title when multiple tests cases exist', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];

globalMock.each`
a | b | expected
${0} | ${1} | ${1}
${1} | ${1} | ${2}
`('expected string', noop);

expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
'expected string',
expectFunction,
);
expect(globalMock).toHaveBeenCalledWith(
'expected string',
expectFunction,
);
});

test('calls global function with title containing param values when using $variable format', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];

globalMock.each`
a | b | expected
${0} | ${1} | ${1}
${1} | ${1} | ${2}
`('expected string: a=$a, b=$b, expected=$expected', noop);

expect(globalMock).toHaveBeenCalledTimes(2);
expect(globalMock).toHaveBeenCalledWith(
'expected string: a=0, b=1, expected=1',
expectFunction,
);
expect(globalMock).toHaveBeenCalledWith(
'expected string: a=1, b=1, expected=2',
expectFunction,
);
});

test('calls global function with cb function containing all parameters of each test case', () => {
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];
const testCallBack = jest.fn();
globalMock.each`
a | b | expected
${0} | ${1} | ${1}
${1} | ${1} | ${2}
`('expected string: %s %s', testCallBack);

globalMock.mock.calls[0][1]();
expect(testCallBack).toHaveBeenCalledTimes(1);

expect(testCallBack).toHaveBeenCalledWith({a: 0, b: 1, expected: 1});

globalMock.mock.calls[1][1]();
expect(testCallBack).toHaveBeenCalledTimes(2);
expect(testCallBack).toHaveBeenCalledWith({a: 1, b: 1, expected: 2});
});

test('calls global function with async done when cb function has more than one argument', () => {
expect.hasAssertions();
const environmentMock = getEnvironmentMock();
installEach(environmentMock);

const globalMock = environmentMock.global[keyPath];
globalMock.each`
a | b | expected
${0} | ${1} | ${1}
`('a title', ({a, b, expected}, done) => {
expect(a).toBe(0);
expect(b).toBe(1);
expect(expected).toBe(1);
expect(done).toBe('DONE');
});

globalMock.mock.calls[0][1]('DONE');
});
});
});
});
Expand Down
Loading

0 comments on commit 36952c5

Please sign in to comment.