Skip to content

Commit a4ba6ab

Browse files
EdJoPaTomaxlath
authored andcommitted
test: use should() instead of .should
1 parent 57b89e4 commit a4ba6ab

24 files changed

+794
-878
lines changed

tests/cirrus_search.ts

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const cirrusSearchPages = cirrusSearchPagesFactory(buildUrl)
88
describe('cirrusSearchPages', () => {
99
it('should generate a URL with the query/search endpoint', () => {
1010
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello' }))
11-
query.action.should.equal('query')
12-
query.list.should.equal('search')
13-
query.srsearch.should.equal('hello')
11+
should(query.action).equal('query')
12+
should(query.list).equal('search')
13+
should(query.srsearch).equal('hello')
1414
should(query.srlimit).not.be.ok()
1515
should(query.srnamespace).not.be.ok()
1616
should(query.sroffset).not.be.ok()
@@ -19,42 +19,43 @@ describe('cirrusSearchPages', () => {
1919
})
2020

2121
it('should accept only the object interface', () => {
22-
cirrusSearchPages.bind(null, 'hello').should.throw()
22+
// @ts-expect-error invalid argument
23+
should(() => cirrusSearchPages('hello')).throw()
2324
})
2425

2526
describe('haswbstatement', () => {
2627
it('should accept a statement argument', () => {
2728
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello', haswbstatement: 'P31=Q5' }))
28-
query.srsearch.should.equal('hello haswbstatement:P31=Q5')
29+
should(query.srsearch).equal('hello haswbstatement:P31=Q5')
2930
})
3031

3132
it('should accept a statement argument alone', () => {
3233
const query = parseUrlQuery(cirrusSearchPages({ haswbstatement: 'P31=Q5' }))
33-
query.srsearch.should.equal('haswbstatement:P31=Q5')
34+
should(query.srsearch).equal('haswbstatement:P31=Q5')
3435
})
3536

3637
it('should accept an array of statements', () => {
3738
const query = parseUrlQuery(cirrusSearchPages({ haswbstatement: [ 'P31=Q5', 'P279=Q2934' ] }))
38-
query.srsearch.should.equal('haswbstatement:P31=Q5 haswbstatement:P279=Q2934')
39+
should(query.srsearch).equal('haswbstatement:P31=Q5 haswbstatement:P279=Q2934')
3940
})
4041

4142
it('should accept negative statements', () => {
4243
const query = parseUrlQuery(cirrusSearchPages({ haswbstatement: '-P31=Q5' }))
43-
query.srsearch.should.equal('-haswbstatement:P31=Q5')
44+
should(query.srsearch).equal('-haswbstatement:P31=Q5')
4445
const query2 = parseUrlQuery(cirrusSearchPages({ haswbstatement: [ 'P31=Q5', '-P279=Q2934' ] }))
45-
query2.srsearch.should.equal('haswbstatement:P31=Q5 -haswbstatement:P279=Q2934')
46+
should(query2.srsearch).equal('haswbstatement:P31=Q5 -haswbstatement:P279=Q2934')
4647
})
4748
})
4849

4950
describe('format', () => {
5051
it('should default to json', () => {
5152
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello' }))
52-
query.format.should.equal('json')
53+
should(query.format).equal('json')
5354
})
5455

5556
it('should accept a custom format', () => {
5657
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello', format: 'xml' }))
57-
query.format.should.equal('xml')
58+
should(query.format).equal('xml')
5859
})
5960
})
6061

@@ -66,26 +67,26 @@ describe('cirrusSearchPages', () => {
6667

6768
it('should accept a single namespace number', () => {
6869
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello', namespace: 0 }))
69-
query.srnamespace.should.equal('0')
70+
should(query.srnamespace).equal('0')
7071
})
7172

7273
it('should accept a single namespace string', () => {
7374
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello', namespace: '0' }))
74-
query.srnamespace.should.equal('0')
75+
should(query.srnamespace).equal('0')
7576
})
7677

7778
it('should accept multiple namespaces as a string', () => {
7879
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello', namespace: '0|1' }))
79-
query.srnamespace.should.equal('0|1')
80+
should(query.srnamespace).equal('0|1')
8081
})
8182

8283
it('should accept multiple namespaces as an array', () => {
8384
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello', namespace: [ 0, 1 ] }))
84-
query.srnamespace.should.equal('0|1')
85+
should(query.srnamespace).equal('0|1')
8586
})
8687

8788
it('should reject an invalid namespace', () => {
88-
cirrusSearchPages.bind(null, { search: 'hello', namespace: 'foo' }).should.throw(/invalid namespace/)
89+
should(() => cirrusSearchPages({ search: 'hello', namespace: 'foo' })).throw(/invalid namespace/)
8990
})
9091
})
9192

@@ -97,11 +98,11 @@ describe('cirrusSearchPages', () => {
9798

9899
it('should accept a custom limit', () => {
99100
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello', limit: 10 }))
100-
query.srlimit.should.equal('10')
101+
should(query.srlimit).equal('10')
101102
})
102103

103104
it('should reject an invalid limit', () => {
104-
cirrusSearchPages.bind(null, { search: 'hello', limit: 'foo' }).should.throw(/invalid limit/)
105+
should(() => cirrusSearchPages({ search: 'hello', limit: 'foo' })).throw(/invalid limit/)
105106
})
106107
})
107108

@@ -113,11 +114,11 @@ describe('cirrusSearchPages', () => {
113114

114115
it('should accept a custom offset', () => {
115116
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello', offset: 10 }))
116-
query.sroffset.should.equal('10')
117+
should(query.sroffset).equal('10')
117118
})
118119

119120
it('should reject an invalid offset', () => {
120-
cirrusSearchPages.bind(null, { search: 'hello', offset: 'foo' }).should.throw(/invalid offset/)
121+
should(() => cirrusSearchPages({ search: 'hello', offset: 'foo' })).throw(/invalid offset/)
121122
})
122123
})
123124

@@ -129,11 +130,12 @@ describe('cirrusSearchPages', () => {
129130

130131
it('should accept a profile', () => {
131132
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello', profile: 'wikibase_prefix_boost' }))
132-
query.srqiprofile.should.equal('wikibase_prefix_boost')
133+
should(query.srqiprofile).equal('wikibase_prefix_boost')
133134
})
134135

135136
it('should reject an invalid profile', () => {
136-
cirrusSearchPages.bind(null, { search: 'hello', profile: 123 }).should.throw(/invalid profile/)
137+
// @ts-expect-error invalid argument
138+
should(() => cirrusSearchPages({ search: 'hello', profile: 123 })).throw(/invalid profile/)
137139
})
138140
})
139141

@@ -145,11 +147,12 @@ describe('cirrusSearchPages', () => {
145147

146148
it('should accept a sort', () => {
147149
const query = parseUrlQuery(cirrusSearchPages({ search: 'hello', sort: 'last_edit_desc' }))
148-
query.srsort.should.equal('last_edit_desc')
150+
should(query.srsort).equal('last_edit_desc')
149151
})
150152

151153
it('should reject an invalid sort', () => {
152-
cirrusSearchPages.bind(null, { search: 'hello', sort: 123 }).should.throw(/invalid sort/)
154+
// @ts-expect-error invalid argument
155+
should(() => cirrusSearchPages({ search: 'hello', sort: 123 })).throw(/invalid sort/)
153156
})
154157
})
155158
})

tests/general.ts

Lines changed: 86 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -4,129 +4,134 @@ import { instance, sparqlEndpoint } from './lib/tests_env.js'
44

55
describe('builder', () => {
66
it('should be a function', () => {
7-
defaultWBK.should.be.a.Function()
8-
WBK.should.be.a.Function()
9-
defaultWBK.should.equal(WBK)
7+
should(defaultWBK).be.a.Function()
8+
should(WBK).be.a.Function()
9+
should(defaultWBK).equal(WBK)
1010
})
1111

1212
it('should reference instance-independant helpers', () => {
1313
should(parse).be.an.Object()
1414
should(simplify).be.an.Object()
15-
parse.entities.should.be.a.Function()
16-
simplify.labels.should.be.a.Function()
17-
simplifySparqlResults.should.be.a.Function()
18-
isEntityId.should.be.a.Function()
19-
getSitelinkData.should.be.a.Function()
15+
should(parse.entities).be.a.Function()
16+
should(simplify.labels).be.a.Function()
17+
should(simplifySparqlResults).be.a.Function()
18+
should(isEntityId).be.a.Function()
19+
should(getSitelinkData).be.a.Function()
2020
})
2121

2222
it('should throw when initialized without a config', () => {
23-
WBK.should.throw()
23+
// @ts-expect-error missing argument
24+
should(() => WBK()).throw()
2425
})
2526

2627
it('should throw when initialized without an instance or a sparqlEndpoint', () => {
27-
(() => WBK({})).should.throw()
28+
should(() => WBK({})).throw()
2829
})
2930

3031
it('should throw when initialized with an invalid instance', () => {
31-
(() => WBK({ instance: 'foo' })).should.throw('invalid instance: foo')
32+
should(() => WBK({ instance: 'foo' })).throw('invalid instance: foo')
3233
})
3334

3435
it('should throw when initialized with an invalid sparql endpoint', () => {
35-
(() => WBK({ instance, sparqlEndpoint: 'foo' })).should.throw('invalid sparqlEndpoint: foo')
36+
should(() => WBK({ instance, sparqlEndpoint: 'foo' })).throw('invalid sparqlEndpoint: foo')
3637
})
3738

3839
it('should not throw when initialized without a sparql endpoint', () => {
3940
const wbk = WBK({ instance })
40-
wbk.sparqlQuery.should.throw('sparqlQuery requires a sparqlEndpoint to be set at initialization')
41-
wbk.getReverseClaims.should.throw('getReverseClaims requires a sparqlEndpoint to be set at initialization')
41+
// @ts-expect-error missing argument
42+
should(() => wbk.sparqlQuery()).throw('sparqlQuery requires a sparqlEndpoint to be set at initialization')
43+
// @ts-expect-error missing argument
44+
should(() => wbk.getReverseClaims()).throw('getReverseClaims requires a sparqlEndpoint to be set at initialization')
4245
})
4346

4447
it('should not throw when initialized without a sparql endpoint', () => {
4548
const wbk = WBK({ sparqlEndpoint })
46-
wbk.searchEntities.should.throw('searchEntities requires an instance to be set at initialization')
47-
wbk.getEntities.should.throw('getEntities requires an instance to be set at initialization')
49+
// @ts-expect-error missing argument
50+
should(() => wbk.searchEntities()).throw('searchEntities requires an instance to be set at initialization')
51+
// @ts-expect-error missing argument
52+
should(() => wbk.getEntities()).throw('getEntities requires an instance to be set at initialization')
4853
})
4954

5055
it('should produce valid URLs', () => {
5156
const wbk = WBK({ instance, sparqlEndpoint })
52-
wbk.searchEntities({ search: 'ingmar Bergman' }).should.startWith(instance)
53-
wbk.getReverseClaims({ properties: 'P50', values: 'Q504' }).should.startWith(sparqlEndpoint)
57+
should(wbk.searchEntities({ search: 'ingmar Bergman' })).startWith(instance)
58+
should(wbk.getReverseClaims({ properties: 'P50', values: 'Q504' })).startWith(sparqlEndpoint)
5459
})
5560

5661
it('should exposed sanitized instance URL', () => {
5762
const wbk = WBK({ instance, sparqlEndpoint })
58-
wbk.instance.root.should.equal(instance)
59-
wbk.instance.apiEndpoint.should.equal(`${instance}/w/api.php`)
63+
should(wbk.instance.root).equal(instance)
64+
should(wbk.instance.apiEndpoint).equal(`${instance}/w/api.php`)
6065
})
6166

6267
it('should allow to customize the script path', () => {
63-
WBK({ instance, wgScriptPath: 'foo' }).instance.apiEndpoint.should.equal(`${instance}/foo/api.php`)
64-
WBK({ instance, wgScriptPath: '/foo' }).instance.apiEndpoint.should.equal(`${instance}/foo/api.php`)
68+
should(WBK({ instance, wgScriptPath: 'foo' }).instance.apiEndpoint).equal(`${instance}/foo/api.php`)
69+
should(WBK({ instance, wgScriptPath: '/foo' }).instance.apiEndpoint).equal(`${instance}/foo/api.php`)
6570
})
6671
})
6772

6873
describe('index', () => {
6974
it('should give access to all the function', () => {
7075
const wbk = WBK({ instance, sparqlEndpoint })
7176

72-
wbk.should.be.an.Object()
73-
74-
wbk.searchEntities.should.be.a.Function()
75-
wbk.cirrusSearchPages.should.be.a.Function()
76-
wbk.getEntities.should.be.a.Function()
77-
wbk.getManyEntities.should.be.a.Function()
78-
wbk.getEntityRevision.should.be.a.Function()
79-
wbk.getReverseClaims.should.be.a.Function()
80-
wbk.getRevisions.should.be.a.Function()
81-
wbk.getEntitiesFromSitelinks.should.be.a.Function()
82-
83-
wbk.simplify.entity.should.be.a.Function()
84-
wbk.simplify.entities.should.be.a.Function()
85-
wbk.simplify.labels.should.be.a.Function()
86-
wbk.simplify.descriptions.should.be.a.Function()
87-
wbk.simplify.aliases.should.be.a.Function()
88-
wbk.simplify.sitelinks.should.be.a.Function()
89-
wbk.simplify.claim.should.be.a.Function()
90-
wbk.simplify.propertyClaims.should.be.a.Function()
91-
wbk.simplify.claims.should.be.a.Function()
92-
wbk.simplify.snak.should.be.a.Function()
93-
wbk.simplify.propertySnaks.should.be.a.Function()
94-
wbk.simplify.snaks.should.be.a.Function()
95-
wbk.simplify.qualifier.should.be.a.Function()
96-
wbk.simplify.propertyQualifiers.should.be.a.Function()
97-
wbk.simplify.qualifiers.should.be.a.Function()
98-
wbk.simplify.forms.should.be.a.Function()
99-
wbk.simplify.form.should.be.a.Function()
100-
wbk.simplify.senses.should.be.a.Function()
101-
wbk.simplify.sense.should.be.a.Function()
102-
wbk.simplify.sparqlResults.should.be.a.Function()
103-
wbk.truthyClaims.should.be.a.Function()
104-
wbk.truthyPropertyClaims.should.be.a.Function()
105-
106-
wbk.parse.entities.should.be.a.Function()
107-
108-
wbk.parse.entities.should.be.a.Function()
109-
wbk.parse.pagesTitles.should.be.a.Function()
110-
111-
wbk.isEntityId.should.be.a.Function()
112-
wbk.isItemId.should.be.a.Function()
113-
wbk.isPropertyId.should.be.a.Function()
114-
wbk.isNumericId.should.be.a.Function()
115-
wbk.isGuid.should.be.a.Function()
116-
wbk.isHash.should.be.a.Function()
117-
wbk.isPropertyClaimsId.should.be.a.Function()
118-
wbk.getNumericId.should.be.a.Function()
119-
wbk.isEntityId.should.be.a.Function()
120-
wbk.isItemId.should.be.a.Function()
121-
wbk.isPropertyId.should.be.a.Function()
122-
wbk.wikibaseTimeToDateObject.should.be.a.Function()
123-
wbk.wikibaseTimeToEpochTime.should.be.a.Function()
124-
wbk.wikibaseTimeToISOString.should.be.a.Function()
125-
wbk.wikibaseTimeToSimpleDay.should.be.a.Function()
126-
wbk.getSitelinkUrl.should.be.a.Function()
127-
wbk.getSitelinkData.should.be.a.Function()
128-
wbk.isSitelinkKey.should.be.a.Function()
129-
wbk.getImageUrl.should.be.a.Function()
130-
wbk.getEntityIdFromGuid.should.be.a.Function()
77+
should(wbk).be.an.Object()
78+
79+
should(wbk.searchEntities).be.a.Function()
80+
should(wbk.cirrusSearchPages).be.a.Function()
81+
should(wbk.getEntities).be.a.Function()
82+
should(wbk.getManyEntities).be.a.Function()
83+
should(wbk.getEntityRevision).be.a.Function()
84+
should(wbk.getReverseClaims).be.a.Function()
85+
should(wbk.getRevisions).be.a.Function()
86+
should(wbk.getEntitiesFromSitelinks).be.a.Function()
87+
88+
should(wbk.simplify.entity).be.a.Function()
89+
should(wbk.simplify.entities).be.a.Function()
90+
should(wbk.simplify.labels).be.a.Function()
91+
should(wbk.simplify.descriptions).be.a.Function()
92+
should(wbk.simplify.aliases).be.a.Function()
93+
should(wbk.simplify.sitelinks).be.a.Function()
94+
should(wbk.simplify.claim).be.a.Function()
95+
should(wbk.simplify.propertyClaims).be.a.Function()
96+
should(wbk.simplify.claims).be.a.Function()
97+
should(wbk.simplify.snak).be.a.Function()
98+
should(wbk.simplify.propertySnaks).be.a.Function()
99+
should(wbk.simplify.snaks).be.a.Function()
100+
should(wbk.simplify.qualifier).be.a.Function()
101+
should(wbk.simplify.propertyQualifiers).be.a.Function()
102+
should(wbk.simplify.qualifiers).be.a.Function()
103+
should(wbk.simplify.forms).be.a.Function()
104+
should(wbk.simplify.form).be.a.Function()
105+
should(wbk.simplify.senses).be.a.Function()
106+
should(wbk.simplify.sense).be.a.Function()
107+
should(wbk.simplify.sparqlResults).be.a.Function()
108+
should(wbk.truthyClaims).be.a.Function()
109+
should(wbk.truthyPropertyClaims).be.a.Function()
110+
111+
should(wbk.parse.entities).be.a.Function()
112+
113+
should(wbk.parse.entities).be.a.Function()
114+
should(wbk.parse.pagesTitles).be.a.Function()
115+
116+
should(wbk.isEntityId).be.a.Function()
117+
should(wbk.isItemId).be.a.Function()
118+
should(wbk.isPropertyId).be.a.Function()
119+
should(wbk.isNumericId).be.a.Function()
120+
should(wbk.isGuid).be.a.Function()
121+
should(wbk.isHash).be.a.Function()
122+
should(wbk.isPropertyClaimsId).be.a.Function()
123+
should(wbk.getNumericId).be.a.Function()
124+
should(wbk.isEntityId).be.a.Function()
125+
should(wbk.isItemId).be.a.Function()
126+
should(wbk.isPropertyId).be.a.Function()
127+
should(wbk.wikibaseTimeToDateObject).be.a.Function()
128+
should(wbk.wikibaseTimeToEpochTime).be.a.Function()
129+
should(wbk.wikibaseTimeToISOString).be.a.Function()
130+
should(wbk.wikibaseTimeToSimpleDay).be.a.Function()
131+
should(wbk.getSitelinkUrl).be.a.Function()
132+
should(wbk.getSitelinkData).be.a.Function()
133+
should(wbk.isSitelinkKey).be.a.Function()
134+
should(wbk.getImageUrl).be.a.Function()
135+
should(wbk.getEntityIdFromGuid).be.a.Function()
131136
})
132137
})

0 commit comments

Comments
 (0)