Skip to content

Commit 34b14b4

Browse files
committed
fix(core base): Do not fail if initialized with an empty jQuery object.
1 parent 7df79e7 commit 34b14b4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/core/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const initBasePattern = function ($el, options, trigger) {
4646
};
4747

4848
const Base = async function ($el, options, trigger) {
49-
if (!$el) {
49+
if (($el?.jquery && $el.length === 0) || !$el) {
5050
log.warn("No element given to pattern.");
5151
return;
5252
}

src/core/base.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ describe("pat-base: The Base class for patterns", function () {
6969
expect(tmp.el).toBeFalsy();
7070
});
7171

72+
it("Does nothing when initialized with an empty jQuery object", function () {
73+
const Tmp = Base.extend({
74+
name: "example",
75+
init: () => {},
76+
});
77+
const tmp = new Tmp($());
78+
expect(tmp instanceof Tmp).toBeTruthy();
79+
expect(tmp.$el).toBeFalsy();
80+
expect(tmp.el).toBeFalsy();
81+
});
82+
7283
it("will automatically register a pattern in the registry when extended", function () {
7384
jest.spyOn(registry, "register");
7485
var NewPattern = Base.extend({

0 commit comments

Comments
 (0)