Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const _ = require('lodash');
- let suite;
- beforeEach(() => {
- suite = {
- sampleData: [1, 2, 3],
- sampleFunc: jest.fn(value => value),
- sampleDataLength: 3
- };
- });
- afterEach(() => {
- suite.sampleFunc.mockClear();
- suite = null;
- });
- describe('lodash wrapper', () => {
- it('toArray', () => {
- const chain = _(suite.sampleData)
- .map(value => suite.sampleFunc(value))
- .toArray();
- expect(suite.sampleFunc).toHaveBeenCalledTimes(suite.sampleDataLength); // 0 times
- console.log(chain.size());
- const first = _.first(chain);
- expect(suite.sampleFunc).toHaveBeenCalledTimes(suite.sampleDataLength); // 3 times
- });
- it('value', () => {
- const chain = _(suite.sampleData)
- .map(value => suite.sampleFunc(value))
- .value();
- expect(suite.sampleFunc).toHaveBeenCalledTimes(suite.sampleDataLength);
- console.log(chain.length);
- const first = _.first(chain);
- expect(suite.sampleFunc).toHaveBeenCalledTimes(suite.sampleDataLength);
- });
- });
- describe('chain', () => {
- it('toArray', () => {
- const chain = _.chain(suite.sampleData)
- .map(value => suite.sampleFunc(value))
- .toArray();
- expect(suite.sampleFunc).toHaveBeenCalledTimes(suite.sampleData.length); // 0 times
- console.log(chain.size());
- const first = _.first(chain);
- expect(suite.sampleFunc).toHaveBeenCalledTimes(suite.sampleData.length); // called 6 times instead of 3
- });
- it('value', () => {
- const chain = _.chain(suite.sampleData)
- .map(value => suite.sampleFunc(value))
- .value();
- expect(suite.sampleFunc).toHaveBeenCalledTimes(suite.sampleDataLength);
- console.log(chain.length);
- const first = _.first(chain);
- expect(suite.sampleFunc).toHaveBeenCalledTimes(suite.sampleDataLength);
- });
- });
Add Comment
Please, Sign In to add comment