Skip to content

Commit 21beaab

Browse files
committed
throw warning instead of error when pagination element not found
1 parent 90065df commit 21beaab

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

src/assert.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,14 @@ export default {
1818
if ($element.length === 0) {
1919
throw new Error(`Element "${elementOrSelector}" not found for "${property}"`);
2020
}
21+
},
22+
warn(fn, ...args) {
23+
try {
24+
fn(...args)
25+
} catch (e) {
26+
if (console && console.warn) {
27+
console.warn(e.message)
28+
}
29+
}
2130
}
2231
}

src/pagination.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class Pagination {
3333
return;
3434
}
3535

36-
Assert.anyElement(this.options.element, 'pagination.element');
36+
Assert.warn(Assert.anyElement, this.options.element, 'pagination.element');
3737

3838
ias.on(Events.BINDED, this.hide.bind(this));
3939
ias.on(Events.UNBINDED, this.restore.bind(this));

test/pagination_spec.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,28 +124,20 @@ describe('Pagination', () => {
124124
});
125125
});
126126

127-
it('should throw when element not found', () => {
127+
it('should warn when element not found', () => {
128128
cy.InfiniteAjaxScroll().then((InfiniteAjaxScroll) => {
129-
const subject = {
130-
ias: () => {
131-
new InfiniteAjaxScroll('.blocks', {
132-
item: '.blocks__block',
133-
next: '.pager__next',
134-
pagination: '.pager_does_not_exist',
135-
bind: false
136-
});
137-
}
138-
};
139-
140-
const spy = cy.spy(subject, 'ias');
141-
142-
try {
143-
subject.ias();
144-
} catch (e) {
145-
// noop
146-
}
129+
cy.window().then((win) => {
130+
const spy = cy.spy(win.console, 'warn');
131+
132+
let ias = new InfiniteAjaxScroll('.blocks', {
133+
item: '.blocks__block',
134+
next: '.pager__next',
135+
pagination: '.pager_does_not_exist',
136+
bind: false
137+
});
147138

148-
expect(spy).to.have.thrown('Error');
139+
expect(spy).to.have.been.called;
140+
});
149141
});
150142
});
151143

0 commit comments

Comments
 (0)