Skip to content

Commit 3b7e923

Browse files
committed
test: Add and improve many test cases
1 parent 96e6070 commit 3b7e923

File tree

5 files changed

+750
-67
lines changed

5 files changed

+750
-67
lines changed

test/unit/css-engine.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ export function lookup(root: Element[], cssSelector: string): Element[] | undefi
116116
// FIXME: Evaluate at-rules and handle them appropriately. This adds a lot of
117117
// complexity, so consider using happy-dom if they have support for it.
118118
export function reduce(elements: Element[]): Record<string, string> {
119+
if (elements.length === 0) return {};
120+
119121
const decls: Record<string, string> = {};
120122

121123
for (const element of elements) {

test/unit/test-css-engine.test.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ const ast = compile(css);
5555

5656
describe('lookup', () => {
5757
test('is a function', () => {
58-
expect.assertions(1);
59-
expect(lookup).toBeInstanceOf(Function);
58+
expect.assertions(2);
59+
expect(lookup).toBeFunction();
60+
expect(lookup).not.toBeClass();
6061
});
6162

6263
test('expects 2 parameters', () => {
@@ -111,8 +112,9 @@ describe('lookup', () => {
111112

112113
describe('walk', () => {
113114
test('is a function', () => {
114-
expect.assertions(1);
115-
expect(walk).toBeInstanceOf(Function);
115+
expect.assertions(2);
116+
expect(walk).toBeFunction();
117+
expect(walk).not.toBeClass();
116118
});
117119

118120
test('expects 2 parameters', () => {
@@ -122,6 +124,7 @@ describe('walk', () => {
122124

123125
test('has no return value', () => {
124126
expect.assertions(1);
127+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
125128
expect(walk(ast, () => {})).toBeUndefined();
126129
});
127130

@@ -146,8 +149,9 @@ describe('walk', () => {
146149

147150
describe('reduce', () => {
148151
test('is a function', () => {
149-
expect.assertions(1);
150-
expect(reduce).toBeInstanceOf(Function);
152+
expect.assertions(2);
153+
expect(reduce).toBeFunction();
154+
expect(reduce).not.toBeClass();
151155
});
152156

153157
test('expects 1 parameter', () => {
@@ -161,11 +165,12 @@ describe('reduce', () => {
161165
expect(reduced).toBePlainObject();
162166
});
163167

164-
test('throws when passed undefined', () => {
165-
expect.assertions(1);
168+
test('throws when passed null or undefined', () => {
169+
expect.assertions(2);
170+
// @ts-expect-error - intentionally passing wrong type
171+
expect(() => reduce(null)).toThrow();
166172
// @ts-expect-error - intentionally passing wrong type
167-
// eslint-disable-next-line unicorn/no-useless-undefined
168-
expect(() => reduce(undefined)).toThrow();
173+
expect(() => reduce()).toThrow();
169174
});
170175

171176
test('merges all elements, overriding earlier values', () => {
@@ -181,8 +186,9 @@ describe('reduce', () => {
181186

182187
describe('cleanElement', () => {
183188
test('is a function', () => {
184-
expect.assertions(1);
185-
expect(cleanElement).toBeInstanceOf(Function);
189+
expect.assertions(2);
190+
expect(cleanElement).toBeFunction();
191+
expect(cleanElement).not.toBeClass();
186192
});
187193

188194
test('expects 1 parameter', () => {
@@ -257,8 +263,9 @@ const notHexColors = [
257263

258264
describe('isHexColor', () => {
259265
test('is a function', () => {
260-
expect.assertions(1);
261-
expect(isHexColor).toBeInstanceOf(Function);
266+
expect.assertions(2);
267+
expect(isHexColor).toBeFunction();
268+
expect(isHexColor).not.toBeClass();
262269
});
263270

264271
test('expects 1 parameter', () => {
@@ -284,8 +291,9 @@ describe('isHexColor', () => {
284291

285292
describe('hexToRgb', () => {
286293
test('is a function', () => {
287-
expect.assertions(1);
288-
expect(hexToRgb).toBeInstanceOf(Function);
294+
expect.assertions(2);
295+
expect(hexToRgb).toBeFunction();
296+
expect(hexToRgb).not.toBeClass();
289297
});
290298

291299
test('expects 1 parameter', () => {
@@ -301,8 +309,9 @@ describe('hexToRgb', () => {
301309

302310
describe('linearize', () => {
303311
test('is a function', () => {
304-
expect.assertions(1);
305-
expect(linearize).toBeInstanceOf(Function);
312+
expect.assertions(2);
313+
expect(linearize).toBeFunction();
314+
expect(linearize).not.toBeClass();
306315
});
307316

308317
test('expects 1 parameter', () => {
@@ -318,8 +327,9 @@ describe('linearize', () => {
318327

319328
describe('luminance', () => {
320329
test('is a function', () => {
321-
expect.assertions(1);
322-
expect(luminance).toBeInstanceOf(Function);
330+
expect.assertions(2);
331+
expect(luminance).toBeFunction();
332+
expect(luminance).not.toBeClass();
323333
});
324334

325335
test('expects 1 parameter', () => {
@@ -335,8 +345,9 @@ describe('luminance', () => {
335345

336346
describe('isLightOrDark', () => {
337347
test('is a function', () => {
338-
expect.assertions(1);
339-
expect(isLightOrDark).toBeInstanceOf(Function);
348+
expect.assertions(2);
349+
expect(isLightOrDark).toBeFunction();
350+
expect(isLightOrDark).not.toBeClass();
340351
});
341352

342353
test('expects 1 parameter', () => {

0 commit comments

Comments
 (0)