Skip to content

Commit

Permalink
test: do not use Array constructor in unit tests (#7548)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Jul 12, 2024
1 parent 4e57d24 commit 347524f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const TEMPLATES = {
const ACTUAL_SIZE = 500;

function dataProvider(params, callback) {
const items = Array(...new Array(params.pageSize)).map((_, i) => {
const items = new Array(params.pageSize).fill().map((_, i) => {
return {
label: `Item ${params.pageSize * params.page + i}`,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/combo-box/test/data-provider.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const TEMPLATES = {
const objectDataProvider = (params, callback) => {
const offset = params.page * params.pageSize;
const n = Math.min(offset + params.pageSize, SIZE) - offset;
dataProviderItems = Array(...new Array(n)).map((_, i) => {
dataProviderItems = new Array(n).fill().map((_, i) => {
return { id: i, value: `value ${i}`, label: `label ${i}` };
});
callback(dataProviderItems, SIZE);
Expand Down
8 changes: 2 additions & 6 deletions packages/dialog/test/draggable-resizable.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,15 @@ describe('resizable', () => {
container.style.height = '100%';
container.style.width = '100%';
container.style.overflow = 'auto';
container.textContent = Array(...new Array(10000))
.map(() => 'foo')
.join(' ');
container.textContent = new Array(10000).fill('foo').join(' ');

const resizeContainer = dialog.$.overlay.$.resizerContainer;
expect(container.offsetHeight).to.equal(resizeContainer.offsetHeight);
});

it('should scroll if the content overflows', () => {
// Fill the content with a lot of text so that it overflows the viewport
dialog.$.overlay.firstElementChild.textContent = Array(...new Array(10000))
.map(() => 'foo')
.join(' ');
dialog.$.overlay.firstElementChild.textContent = new Array(10000).fill('foo').join(' ');

const resizeContainer = dialog.$.overlay.$.resizerContainer;
resizeContainer.scrollTop = 1;
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/test/accessibility.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ describe('accessibility', () => {
});

it('should update aria-rowcount on after size change', () => {
grid.items = Array(...new Array(10)).map(() => 'foo');
grid.items = new Array(10).fill('foo');

// 10 item rows + header row + footer row = 12 in total
expect(grid.$.table.getAttribute('aria-rowcount')).to.equal('12');
Expand Down
8 changes: 4 additions & 4 deletions packages/grid/test/scroll-to-index.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('scroll to index', () => {
grid.dataProvider = ({ parentItem }, cb) => {
setTimeout(() => {
const scope = parentItem || '';
cb(Array(...new Array(grid.pageSize)).map((_, index) => `${scope}foo${index}`));
cb(new Array(grid.pageSize).fill().map((_, index) => `${scope}foo${index}`));
if (parentItem) {
expect(getFirstVisibleItem(grid).index).to.be.above(75);
done();
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('scroll to index', () => {
// Still in loading state, this will end up as pending scroll to index
grid.scrollToIndex(100);
// Resolve the request, no longer in loading state after this
cb(Array(...new Array(grid.pageSize)).map((_, index) => `foo${index}`));
cb(new Array(grid.pageSize).fill().map((_, index) => `foo${index}`));
flushGrid(grid);

// Scroll to a new location (new data will get loaded)
Expand All @@ -186,7 +186,7 @@ describe('scroll to index', () => {
expect(getFirstVisibleItem(grid).index).to.be.above(150);
done();
} else {
cb(Array(...new Array(grid.pageSize)).map((_, index) => `foo${index}`));
cb(new Array(grid.pageSize).fill().map((_, index) => `foo${index}`));
}
};
});
Expand All @@ -197,7 +197,7 @@ describe('scroll to index', () => {

beforeEach(() => {
grid = fixtures.large();
data = Array(...new Array(10)).map((_, i) => {
data = new Array(10).fill().map((_, i) => {
return { index: i };
});

Expand Down

0 comments on commit 347524f

Please sign in to comment.