Skip to content

Commit

Permalink
Throw runtime error if jQuery not available
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-nicka committed Mar 30, 2020
1 parent de64f4a commit 2ef06ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/labkey/dom/Utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2020 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { loadDOMContext } from './constants';

describe('loadDOMContext', () => {

it('Error without jQuery', () => {
const { $ } = loadDOMContext();
expect(() => { $(); }).toThrowError('jQuery');
});
});
4 changes: 3 additions & 1 deletion src/labkey/dom/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ if (typeof jQuery !== 'undefined') {
LABKEY.$ = jQuery;
}
else {
console.warn('jQuery not available. When using the DOM version of the LabKey API jQuery is expected to be available.');
LABKEY.$ = () => {
throw new Error('jQuery not available. When using the DOM version of the LabKey API jQuery is expected to be available.');
};
}

export function loadDOMContext(): LabKeyDOM {
Expand Down

0 comments on commit 2ef06ce

Please sign in to comment.