Skip to content

Commit 72d5d75

Browse files
committed
fix test failure and type errors
1 parent 4251740 commit 72d5d75

8 files changed

Lines changed: 63 additions & 43 deletions

File tree

test/helpers/jest-matchers.d.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { IndexedFormula } from 'rdflib'
2+
3+
declare global {
4+
namespace jest {
5+
interface Matchers<R, T = unknown> {
6+
toContainGraph(expected: IndexedFormula): R
7+
toEqualGraph(expected: IndexedFormula): R
8+
toBeCalled(): R
9+
toBeCalledWith(...args: any[]): R
10+
toReturn(): R
11+
toThrowError(error?: any): R
12+
}
13+
}
14+
}
15+
16+
export {}

test/helpers/setup.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ import { TransformStream, ReadableStream, WritableStream } from 'stream/web'
77
// https://stackoverflow.com/questions/52612122/how-to-use-jest-to-test-functions-using-crypto-or-window-mscrypto
88

99
import crypto from 'crypto'
10-
global.crypto = {
11-
getRandomValues: function (buffer) {
12-
return crypto.randomFillSync(buffer)
13-
}
14-
}
10+
Object.defineProperty(globalThis, 'crypto', {
11+
value: crypto.webcrypto,
12+
configurable: true
13+
})
1514

1615
global.TextEncoder = TextEncoder
1716
global.TextDecoder = TextDecoder
18-
global.TransformStream = TransformStream
19-
global.ReadableStream = ReadableStream
20-
global.WritableStream = WritableStream
17+
global.TransformStream = TransformStream as unknown as typeof globalThis.TransformStream
18+
global.ReadableStream = ReadableStream as unknown as typeof globalThis.ReadableStream
19+
global.WritableStream = WritableStream as unknown as typeof globalThis.WritableStream
2120

2221
// Node provides MessagePort via worker_threads; jsdom/undici expects it in global scope
2322
try {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`tabWidget minimal setup of options renders content for first tab 1`] = `
4-
<main
4+
<div
55
style="margin: 0; width:100%; height: 100%;"
66
>
77
<div
88
style="height: 100%; width: 100%;"
99
>
10-
<main
10+
<div
1111
style="display: grid; width: auto; height: 100%; border: 0.1em; border-style: solid; border-color: #e7e7db; padding: 1em;"
1212
/>
1313
</div>
1414
<div
1515
style="height: 100%; width: 100%;display: none;"
1616
/>
17-
</main>
17+
</div>
1818
`;

test/unit/acl/acl.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ describe('getACL', () => {
156156
case DEFAULT_RESOURCE_DOC:
157157
solidLogicSingleton.store.add(DEFAULT_RESOURCE_DOC, ACL_LINK, DEFAULT_RESOURCE_ACL, DEFAULT_RESOURCE_DOC)
158158
// eslint-disable-next-line n/no-callback-literal
159-
return callback(true)
159+
return callback?.(true, '')
160160
case DEFAULT_RESOURCE_ACL:
161161
// eslint-disable-next-line n/no-callback-literal
162-
return callback(true)
162+
return callback?.(true, '')
163163
}
164164
}
165165
getACL(DEFAULT_RESOURCE_DOC, callbackFunction)
@@ -174,7 +174,7 @@ describe('getACL', () => {
174174
solidLogicSingleton.store.add(DEFAULT_RESOURCE_DOC, ACL_LINK, DEFAULT_RESOURCE_ACL, DEFAULT_RESOURCE_DOC)
175175
solidLogicSingleton.store.fetcher.nonexistent[DEFAULT_RESOURCE_ACL.uri] = true
176176
// eslint-disable-next-line n/no-callback-literal
177-
return callback(true)
177+
return callback?.(true, '')
178178
}
179179
getACL(DEFAULT_RESOURCE_DOC, callbackFunction)
180180
})
@@ -191,10 +191,10 @@ describe('getACL', () => {
191191
case DEFAULT_RESOURCE_DOC:
192192
solidLogicSingleton.store.add(DEFAULT_RESOURCE_DOC, ACL_LINK, DEFAULT_RESOURCE_ACL, DEFAULT_RESOURCE_DOC)
193193
// eslint-disable-next-line n/no-callback-literal
194-
return callback(true)
194+
return callback?.(true, '')
195195
case DEFAULT_RESOURCE_ACL:
196196
// eslint-disable-next-line n/no-callback-literal
197-
return callback(false, errorMessage, { status: 500 })
197+
return callback?.(false, errorMessage, { status: 500 } as Response)
198198
}
199199
}
200200
getACL(DEFAULT_RESOURCE_DOC, callbackFunction)
@@ -207,7 +207,7 @@ describe('getACL', () => {
207207
describe('no ACL link for resource', () => {
208208
beforeEach(() => {
209209
// eslint-disable-next-line n/no-callback-literal
210-
solidLogicSingleton.store.fetcher.nowOrWhenFetched = (doc, options, callback) => callback(true)
210+
solidLogicSingleton.store.fetcher.nowOrWhenFetched = (doc, options, callback) => callback?.(true, '')
211211
getACL(DEFAULT_RESOURCE_DOC, callbackFunction)
212212
})
213213

@@ -217,7 +217,7 @@ describe('getACL', () => {
217217
describe('failed response for doc', () => {
218218
beforeEach(() => {
219219
// eslint-disable-next-line n/no-callback-literal
220-
solidLogicSingleton.store.fetcher.nowOrWhenFetched = (doc, options, callback) => callback(false, 'Failed response')
220+
solidLogicSingleton.store.fetcher.nowOrWhenFetched = (doc, options, callback) => callback?.(false, 'Failed response')
221221
getACL(DEFAULT_RESOURCE_DOC, callbackFunction)
222222
})
223223

test/unit/tabs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('tabWidget', () => {
7676

7777
describe('bodyContainer', () => {
7878
it('adds property bodyContainer', () => {
79-
expect(tabWidgetElement.bodyContainer).toBe(tabWidgetElement.querySelector('main'))
79+
expect(tabWidgetElement.bodyContainer).toBe(tabWidgetElement.querySelector('nav + div'))
8080
})
8181
})
8282

@@ -123,7 +123,7 @@ describe('tabWidget', () => {
123123
tabWidgetElement = tabs.tabWidget({ backgroundColor: '#ff0000', ...minimalOptions })
124124
expect(tabWidgetElement.tabContainer.querySelector('[style]').style['background-color']).toEqual('rgb(178, 0, 0)')
125125
expect(tabWidgetElement.tabContainer.querySelector('[style]').style.color).toEqual('rgb(255, 255, 255)')
126-
expect(tabWidgetElement.bodyContainer.querySelector('main').style['border-color']).toEqual('rgb(178, 0, 0)')
126+
expect((tabWidgetElement.bodyContainer.children[0].children[0] as HTMLElement).style.borderColor).toEqual('rgb(178, 0, 0)')
127127
})
128128

129129
it('considers lighter colors and set color of text accordingly', () => {

test/unit/widgets/forms/basic.test.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import { style } from '../../../../src/style'
1010
import { clearStore } from '../../helpers/clearStore'
1111
import { store } from 'solid-logic'
1212

13+
const mockUpdater = store.updater as typeof store.updater & {
14+
updated: boolean
15+
reportSuccess: boolean
16+
}
17+
1318
silenceDebugMessages()
1419
afterEach(clearStore)
1520

@@ -292,7 +297,7 @@ describe('basicField', () => {
292297
inputElement.value = 'changed value'
293298
const event = new Event('change')
294299
inputElement.dispatchEvent(event)
295-
expect(store.updater.updated).toEqual(true)
300+
expect(mockUpdater.updated).toEqual(true)
296301
})
297302

298303
it('defers date change while focused', () => {
@@ -441,7 +446,7 @@ describe('basicField', () => {
441446
inputElement.value = 'http://example.com/#changed-value'
442447
const event = new Event('change')
443448
inputElement.dispatchEvent(event)
444-
expect(store.updater.updated).toEqual(true)
449+
expect(mockUpdater.updated).toEqual(true)
445450
})
446451

447452
it('calls updater on change for a field with uriPrefix', () => {
@@ -470,7 +475,7 @@ describe('basicField', () => {
470475
inputElement.value = '999000'
471476
const event = new Event('change')
472477
inputElement.dispatchEvent(event)
473-
expect(store.updater.updated).toEqual(true)
478+
expect(mockUpdater.updated).toEqual(true)
474479
})
475480

476481
it('calls updater on change for a field with dt', () => {
@@ -484,7 +489,7 @@ describe('basicField', () => {
484489
const callbackFunction = jest.fn() // TODO: https://github.com/solidos/solid-ui/issues/263
485490
store.add(form, ns.ui('property'), property, doc)
486491
store.add(form, ns.rdf('type'), formType, doc)
487-
store.add(subject, property, 1.1111, doc)
492+
store.add(subject, property, lit('1.1111'), doc)
488493

489494
const result = basicField(
490495
document,
@@ -499,7 +504,7 @@ describe('basicField', () => {
499504
inputElement.value = '9.99000'
500505
const event = new Event('change')
501506
inputElement.dispatchEvent(event)
502-
expect(store.updater.updated).toEqual(true)
507+
expect(mockUpdater.updated).toEqual(true)
503508
})
504509

505510
it('creates triple if missing', () => {
@@ -525,7 +530,7 @@ describe('basicField', () => {
525530
inputElement.value = '9.99000'
526531
const event = new Event('change')
527532
inputElement.dispatchEvent(event)
528-
expect(store.updater.updated).toEqual(true)
533+
expect(mockUpdater.updated).toEqual(true)
529534
})
530535

531536
it('Can update multiple docs', () => {
@@ -540,9 +545,9 @@ describe('basicField', () => {
540545
const callbackFunction = jest.fn() // TODO: https://github.com/solidos/solid-ui/issues/263
541546
store.add(form, ns.ui('property'), property, doc1)
542547
store.add(form, ns.rdf('type'), formType, doc1)
543-
store.add(subject, property, 1.1111, doc1)
544-
store.add(subject, property, 1.5, doc1)
545-
store.add(subject, property, 1.1111, doc2)
548+
store.add(subject, property, lit('1.1111'), doc1)
549+
store.add(subject, property, lit('1.5'), doc1)
550+
store.add(subject, property, lit('1.1111'), doc2)
546551

547552
const result = basicField(
548553
document,
@@ -557,7 +562,7 @@ describe('basicField', () => {
557562
inputElement.value = '1.1111'
558563
const event = new Event('change')
559564
inputElement.dispatchEvent(event)
560-
expect(store.updater.updated).toEqual(true)
565+
expect(mockUpdater.updated).toEqual(true)
561566
})
562567

563568
it('Reports update success', () => {
@@ -569,7 +574,7 @@ describe('basicField', () => {
569574
const doc = namedNode('http://example.com/')
570575
const callbackFunction = jest.fn() // TODO: https://github.com/solidos/solid-ui/issues/263
571576
store.add(form, ns.ui('property'), property, doc)
572-
store.add(subject, property, 1.1111, doc)
577+
store.add(subject, property, lit('1.1111'), doc)
573578

574579
const result = basicField(
575580
document,
@@ -583,7 +588,7 @@ describe('basicField', () => {
583588
const inputElement = result.childNodes[1].childNodes[0] as HTMLInputElement
584589
inputElement.value = '1.1111'
585590
const event = new Event('change')
586-
store.updater.reportSuccess = true
591+
mockUpdater.reportSuccess = true
587592
inputElement.dispatchEvent(event)
588593
expect(callbackFunction.mock.calls).toEqual([[true, 'body']])
589594
})
@@ -597,7 +602,7 @@ describe('basicField', () => {
597602
const doc = namedNode('http://example.com/')
598603
const callbackFunction = jest.fn() // TODO: https://github.com/solidos/solid-ui/issues/263
599604
store.add(form, ns.ui('property'), property, doc)
600-
store.add(subject, property, 1.1111, doc)
605+
store.add(subject, property, lit('1.1111'), doc)
601606

602607
const result = basicField(
603608
document,
@@ -611,7 +616,7 @@ describe('basicField', () => {
611616
const inputElement = result.childNodes[1].childNodes[0] as HTMLInputElement
612617
inputElement.value = '1.1111'
613618
const event = new Event('change')
614-
store.updater.reportSuccess = false
619+
mockUpdater.reportSuccess = false
615620
inputElement.dispatchEvent(event)
616621
expect(callbackFunction.mock.calls).toEqual([[false, 'body']])
617622
})
@@ -626,8 +631,8 @@ describe('basicField', () => {
626631
const doc2 = namedNode('http://example.com/2')
627632
const callbackFunction = jest.fn() // TODO: https://github.com/solidos/solid-ui/issues/263
628633
store.add(form, ns.ui('property'), property, doc)
629-
store.add(subject, property, 1.1111, doc)
630-
store.add(subject, property, 1.1111, doc2)
634+
store.add(subject, property, lit('1.1111'), doc)
635+
store.add(subject, property, lit('1.1111'), doc2)
631636

632637
const result = basicField(
633638
document,
@@ -641,7 +646,7 @@ describe('basicField', () => {
641646
const inputElement = result.childNodes[1].childNodes[0] as HTMLInputElement
642647
inputElement.value = '1.1111'
643648
const event = new Event('change')
644-
store.updater.reportSuccess = false
649+
mockUpdater.reportSuccess = false
645650
inputElement.dispatchEvent(event)
646651
expect(callbackFunction.mock.calls).toEqual([[false, 'body']])
647652
})
@@ -856,7 +861,7 @@ describe('basicField', () => {
856861
const callbackFunction = jest.fn() // TODO: https://github.com/solidos/solid-ui/issues/263
857862
store.add(form, ns.rdf('type'), formType, doc)
858863
store.add(form, ns.ui('property'), property, doc)
859-
store.add(form, ns.ui('size'), 30, doc)
864+
store.add(form, ns.ui('size'), lit('30'), doc)
860865
store.add(subject, property, namedNode('tel:123412341234'), doc)
861866

862867
const result = basicField(
@@ -932,7 +937,7 @@ describe('basicField', () => {
932937
const doc = namedNode('http://example.com/')
933938
const callbackFunction = jest.fn() // TODO: https://github.com/solidos/solid-ui/issues/263
934939
store.add(form, ns.ui('property'), property, doc)
935-
store.add(form, ns.ui('maxLength'), 100, doc)
940+
store.add(form, ns.ui('maxLength'), lit('100'), doc)
936941
store.add(subject, property, namedNode('tel:123412341234'), doc)
937942

938943
const result = basicField(

test/unit/widgets/peoplePicker.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { silenceDebugMessages } from '../helpers/debugger'
33
// SHARON IS WORKING ON THIS FILE
44
// NOT DOING ANYTHING FOR NOW AS SHE WILL CLEAN IT UP LATER
55
silenceDebugMessages()
6-
it.skip('only here to make tests run', () => null)
6+
it.skip('only here to make tests run', () => {})
77

88
// import * as RdfLib from 'rdflib'
99
// import { JSDOM } from 'jsdom'

test/unit/widgets/widgetHelpers.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ describe('wrapDivInATR ', () => {
2525
const obj = namedNode('https://test.com/#name')
2626
it('wraps a given div in a tr and td', () => {
2727
wrapDivInATR(dom, element, obj)
28-
expect(element.parentElement.nodeName).toEqual('TD')
29-
expect(element.parentElement.parentElement.nodeName).toEqual('TR')
28+
expect(element.parentElement!.nodeName).toEqual('TD')
29+
expect(element.parentElement!.parentElement!.nodeName).toEqual('TR')
3030
})
3131
})
3232

@@ -42,7 +42,7 @@ describe('addClickListenerToElement', () => {
4242
describe('createImageDiv', () => {
4343
it('creates a div for the image and attaches them to the element', () => {
4444
createImageDiv(dom, element, image)
45-
expect(image.parentElement.nodeName).toEqual('DIV')
45+
expect(image.parentElement!.nodeName).toEqual('DIV')
4646
expect(element.children[0].nodeName).toEqual('DIV')
4747
})
4848

0 commit comments

Comments
 (0)