react-bootstrap-table2/packages/react-bootstrap-table2-example/test/utils/common.test.js
ChunMing, Chen f9ccbd0717 examples enhance
* utils for products generator

* load test for each *.test.js file in packages folder

* [test] unit test for utils/common

* refactor all products with productGenerator for all examples

* refactor folder structure

* move component <Code /> to src/components/common
* rename component file name
2017-09-04 08:46:01 -05:00

37 lines
1.1 KiB
JavaScript

import { productsGenerator } from '../../src/utils/common';
describe('Utils', () => {
describe('productsGenerator', () => {
const quantity = 2;
it('should return an array', () => {
expect(Array.isArray(productsGenerator())).toBe(true);
});
it('should return 5 products without params', () => {
expect(productsGenerator().length).toEqual(5);
});
it('should return an array with given quntity', () => {
expect(productsGenerator(quantity).length).toEqual(quantity);
});
describe('when callback is defined', () => {
const callback = (value, index) => ({
id: index,
name: 'react-bootstrap-table-2'
});
it('should return customized products format', () => {
const products = productsGenerator(quantity, callback);
const product = products[0];
expect(Array.isArray(products)).toBe(true);
expect(products.length).toBe(quantity);
expect(product).toHaveProperty('id', 0);
expect(product).toHaveProperty('name', 'react-bootstrap-table-2');
});
});
});
});