Skip to content

Commit

Permalink
test: Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmilton committed Jul 15, 2024
1 parent 08dfc0f commit be48230
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/unit/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('store', () => {
test('returns a Proxy', () => {
expect.assertions(1);
const state = store({});
expect(isProxy(state)).toBe(true);
expect(isProxy(state)).toBeTrue();
});

test('returns an object with the same properties', () => {
Expand Down
103 changes: 97 additions & 6 deletions test/unit/test-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ describe('matcher: toHaveParameters', () => {
[0, 2, async function foo(_a = 1, _b = 2) {}],
// eslint-disable-next-line @typescript-eslint/no-empty-function
[0, 3, async function foo(_a = 1, _b = 2, ..._rest: unknown[]) {}],
// eslint-disable-next-line @typescript-eslint/no-empty-function
[0, 0, async function* foo() {}],
// eslint-disable-next-line @typescript-eslint/no-empty-function
[1, 0, async function* foo(_a: unknown) {}],
// eslint-disable-next-line @typescript-eslint/no-empty-function
[0, 1, async function* foo(_a = 1) {}],
// eslint-disable-next-line @typescript-eslint/no-empty-function
[2, 0, async function* foo(_a: unknown, _b: unknown) {}],
// eslint-disable-next-line @typescript-eslint/no-empty-function
[1, 1, async function* foo(_a: unknown, _b = 1) {}],
// eslint-disable-next-line @typescript-eslint/no-empty-function
[0, 2, async function* foo(_a = 1, _b = 2) {}],
// eslint-disable-next-line @typescript-eslint/no-empty-function
[0, 3, async function* foo(_a = 1, _b = 2, ..._rest: unknown[]) {}],
// eslint-disable-next-line @typescript-eslint/no-empty-function, func-names
[0, 0, function* () {}],
// eslint-disable-next-line @typescript-eslint/no-empty-function, func-names
Expand Down Expand Up @@ -246,6 +260,13 @@ describe('matcher: toHaveParameters', () => {
[0, 2, async function (_a = 1, _b = 2) {}], // eslint-disable-line @typescript-eslint/no-empty-function, func-names
// biome-ignore lint/complexity/useArrowFunction: explicit test case
[0, 3, async function (_a = 1, _b = 2, ..._rest: unknown[]) {}], // eslint-disable-line @typescript-eslint/no-empty-function, func-names
[0, 0, async function* () {}], // eslint-disable-line @typescript-eslint/no-empty-function, func-names
[1, 0, async function* (_a: unknown) {}], // eslint-disable-line @typescript-eslint/no-empty-function, func-names
[0, 1, async function* (_a = 1) {}], // eslint-disable-line @typescript-eslint/no-empty-function, func-names
[2, 0, async function* (_a: unknown, _b: unknown) {}], // eslint-disable-line @typescript-eslint/no-empty-function, func-names
[1, 1, async function* (_a: unknown, _b = 1) {}], // eslint-disable-line @typescript-eslint/no-empty-function, func-names
[0, 2, async function* (_a = 1, _b = 2) {}], // eslint-disable-line @typescript-eslint/no-empty-function, func-names
[0, 3, async function* (_a = 1, _b = 2, ..._rest: unknown[]) {}], // eslint-disable-line @typescript-eslint/no-empty-function, func-names
[0, 0, async () => {}],
[1, 0, async (_a: unknown) => {}],
[0, 1, async (_a = 1) => {}],
Expand Down Expand Up @@ -395,6 +416,15 @@ describe('parameters', () => {
expect(parameters(foo)).toBe(0);
});

test('async generator function', () => {
expect.assertions(1);
async function* foo() {
await Promise.resolve();
yield null;
}
expect(parameters(foo)).toBe(0);
});

test('arrow function', () => {
expect.assertions(1);
const foo = () => {};
Expand Down Expand Up @@ -848,6 +878,15 @@ describe('parameters', () => {
expect(parameters(foo)).toBe(2);
});

test('async generator function declaration and expression', () => {
expect.assertions(1);
const foo = async function* foo(_a: unknown, _b: unknown) {
await Promise.resolve();
yield null;
};
expect(parameters(foo)).toBe(2);
});

test('function expression', () => {
expect.assertions(1);
// biome-ignore lint/complexity/useArrowFunction: explicit test case
Expand All @@ -873,6 +912,15 @@ describe('parameters', () => {
expect(parameters(bar)).toBe(2);
});

test('async generator function expression', () => {
expect.assertions(1);
const bar = async function* (_a: unknown, _b: unknown) /* eslint-disable-line func-names */ {
await Promise.resolve();
yield null;
};
expect(parameters(bar)).toBe(2);
});

test('arrow function expression', () => {
expect.assertions(1);
const bar = (_a: unknown, _b: unknown) => {};
Expand Down Expand Up @@ -908,6 +956,15 @@ describe('parameters', () => {
}
expect(parameters(baz)).toBe(2);
});

test('async generator function declaration', () => {
expect.assertions(1);
async function* baz(_a: unknown, _b: unknown) {
await Promise.resolve();
yield null;
}
expect(parameters(baz)).toBe(2);
});
});

/* eslint-disable @typescript-eslint/lines-between-class-members, @typescript-eslint/no-empty-function, @typescript-eslint/no-extraneous-class, @typescript-eslint/no-invalid-void-type, @typescript-eslint/no-useless-constructor, class-methods-use-this */
Expand Down Expand Up @@ -1024,13 +1081,30 @@ describe('parameters', () => {
class Foo {
// biome-ignore lint/complexity/noUselessConstructor: simple test case
constructor(_a: unknown, _b: unknown) {}
async method(this: void, _c: unknown, _d: unknown, _e: unknown) {}
async method(this: void, _c: unknown, _d: unknown, _e: unknown) {
await Promise.resolve();
}
}
const instance = new Foo(1, 2);
expect(parameters(instance.method)).toBe(3);
});

test('case 6: async generator method parameters', () => {
expect.assertions(1);
class Foo {
// biome-ignore lint/complexity/noUselessConstructor: simple test case
constructor(_a: unknown, _b: unknown) {}
// eslint-disable-next-line generator-star-spacing
async *method(this: void, _c: unknown, _d: unknown, _e: unknown) {
await Promise.resolve();
yield null;
}
}
const instance = new Foo(1, 2);
expect(parameters(instance.method)).toBe(3);
});

test('case 6: anonymous method parameters', () => {
test('case 7: anonymous method parameters', () => {
expect.assertions(1);
const instance = new (class {
// biome-ignore lint/complexity/noUselessConstructor: simple test case
Expand All @@ -1040,7 +1114,7 @@ describe('parameters', () => {
expect(parameters(instance.method)).toBe(3);
});

test('case 7: field parameters', () => {
test('case 8: field parameters', () => {
expect.assertions(1);
class Foo {
method = (_a: unknown, _b: unknown, _c: unknown) => {};
Expand Down Expand Up @@ -1098,12 +1172,28 @@ describe('parameters', () => {
class Foo {
// biome-ignore lint/complexity/noUselessConstructor: simple test case
constructor(_a: unknown, _b: unknown) {}
static async method(this: void, _c: unknown, _d: unknown, _e: unknown) {}
static async method(this: void, _c: unknown, _d: unknown, _e: unknown) {
await Promise.resolve();
}
}
expect(parameters(Foo.method)).toBe(3);
});

test('case 6: async generator method parameters', () => {
expect.assertions(1);
class Foo {
// biome-ignore lint/complexity/noUselessConstructor: simple test case
constructor(_a: unknown, _b: unknown) {}
// eslint-disable-next-line generator-star-spacing
static async *method(this: void, _c: unknown, _d: unknown, _e: unknown) {
await Promise.resolve();
yield null;
}
}
expect(parameters(Foo.method)).toBe(3);
});

test('case 6: anonymous method parameters', () => {
test('case 7: anonymous method parameters', () => {
expect.assertions(1);
expect(
parameters(
Expand All @@ -1116,7 +1206,7 @@ describe('parameters', () => {
).toBe(3);
});

test('case 7: field parameters', () => {
test('case 8: field parameters', () => {
expect.assertions(1);
// biome-ignore lint/complexity/noStaticOnlyClass: explicit test case
class Foo /* eslint-disable-line unicorn/no-static-only-class */ {
Expand Down Expand Up @@ -1288,6 +1378,7 @@ describe('parameters', () => {
['console', console],
['window', window],
['document', document],
['chrome', chrome],

Check failure on line 1381 in test/unit/test-setup.test.ts

View workflow job for this annotation

GitHub Actions / test

ReferenceError: Can't find variable: chrome

at closure (/home/runner/work/stage1/stage1/test/unit/test-setup.test.ts:1381:24) at /home/runner/work/stage1/stage1/test/unit/test-setup.test.ts:1330:3 at /home/runner/work/stage1/stage1/test/unit/test-setup.test.ts:395:1

Check failure on line 1381 in test/unit/test-setup.test.ts

View workflow job for this annotation

GitHub Actions / test

ReferenceError: Can't find variable: chrome

at closure (/home/runner/work/stage1/stage1/test/unit/test-setup.test.ts:1381:24) at /home/runner/work/stage1/stage1/test/unit/test-setup.test.ts:1330:3 at /home/runner/work/stage1/stage1/test/unit/test-setup.test.ts:395:1
['process', process],
['global', global],
['globalThis', globalThis],
Expand Down

0 comments on commit be48230

Please sign in to comment.