Skip to content

Commit ccb67fb

Browse files
committed
chore(common): BIG-0 Fix linting issues
1 parent b48ee1c commit ccb67fb

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

src/script-loader.spec.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,28 @@ describe('ScriptLoader', () => {
8282
'https://code.jquery.com/jquery-3.2.1.min.js',
8383
{async: true, attributes: {'data-attribute1': '1', 'data-attribute2': '2'}});
8484

85-
expect(script.attributes.getNamedItem('data-attribute1')!.value)
86-
.toEqual('1');
85+
const attr1 = script.attributes.getNamedItem('data-attribute1');
86+
expect(attr1).not.toBeNull();
87+
expect(attr1?.value).toEqual('1');
8788

88-
expect(script.attributes.getNamedItem('data-attribute2')!.value)
89-
.toEqual('2');
89+
const attr2 = script.attributes.getNamedItem('data-attribute2');
90+
expect(attr2).not.toBeNull();
91+
expect(attr2?.value).toEqual('2');
9092
});
9193
});
9294

9395
describe('when script fails to load', () => {
9496
beforeEach(() => {
9597
jest.spyOn(document.body, 'appendChild')
9698
.mockImplementation(element => {
97-
setTimeout(() => (element as HTMLElement).onerror!(new Event('error')), 0);
99+
setTimeout(() => {
100+
const onerror = (element as HTMLElement & {
101+
onerror?(this: HTMLElement, ev: Event): any;
102+
}).onerror;
103+
if (typeof onerror === 'function') {
104+
onerror.call(element as HTMLElement, new Event('error'));
105+
}
106+
}, 0);
98107

99108
return element;
100109
});
@@ -187,7 +196,14 @@ describe('ScriptLoader', () => {
187196

188197
jest.spyOn(document.head, 'appendChild')
189198
.mockImplementation(element => {
190-
setTimeout(() => (element as HTMLElement).onload!(new Event('load')), 0);
199+
setTimeout(() => {
200+
const onload = (element as HTMLElement & {
201+
onload?(this: HTMLElement, ev: Event): any;
202+
}).onload;
203+
if (typeof onload === 'function') {
204+
onload.call(element as HTMLElement, new Event('load'));
205+
}
206+
}, 0);
191207

192208
return element;
193209
});

src/stylesheet-loader.spec.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ describe('StylesheetLoader', () => {
3737
beforeEach(() => {
3838
jest.spyOn(document.head, 'appendChild')
3939
.mockImplementation(element => {
40-
setTimeout(() => (element as HTMLElement).onload!(new Event('load')), 0);
40+
setTimeout(() => {
41+
const onload = (element as HTMLElement & {
42+
onload?(this: HTMLElement, ev: Event): any;
43+
}).onload;
44+
if (typeof onload === 'function') {
45+
onload.call(element as HTMLElement, new Event('load'));
46+
}
47+
}, 0);
4148

4249
return element;
4350
});
@@ -73,19 +80,26 @@ describe('StylesheetLoader', () => {
7380
'https://foo.bar/hello-world.css',
7481
{prepend: true, attributes: {'data-attribute1': '1', 'data-attribute2': '2'}});
7582

76-
expect(stylesheet.attributes.getNamedItem('data-attribute1')!.value)
77-
.toEqual('1');
83+
const attr1 = stylesheet.attributes.getNamedItem('data-attribute1');
84+
expect(attr1).not.toBeNull();
85+
expect(attr1?.value).toEqual('1');
7886

79-
expect(stylesheet.attributes.getNamedItem('data-attribute2')!.value)
80-
.toEqual('2');
87+
const attr2 = stylesheet.attributes.getNamedItem('data-attribute2');
88+
expect(attr2).not.toBeNull();
89+
expect(attr2?.value).toEqual('2');
8190
});
8291
});
8392

8493
describe('when stylesheet fails to load', () => {
8594
beforeEach(() => {
8695
jest.spyOn(document.head, 'appendChild')
8796
.mockImplementation(element => {
88-
setTimeout(() => (element as HTMLElement).onerror!(new Event('error')), 0);
97+
setTimeout(() => {
98+
const onerror = (element as HTMLElement).onerror;
99+
if (typeof onerror === 'function') {
100+
onerror(new Event('error'));
101+
}
102+
}, 0);
89103

90104
return element;
91105
});
@@ -127,7 +141,9 @@ describe('StylesheetLoader', () => {
127141

128142
jest.spyOn(document.head, 'appendChild')
129143
.mockImplementation(element => {
130-
setTimeout(() => (element as HTMLElement).onload!(new Event('load')), 0);
144+
setTimeout(() => {
145+
element.dispatchEvent(new Event('load'));
146+
}, 0);
131147

132148
return element;
133149
});

0 commit comments

Comments
 (0)