Skip to content

Commit

Permalink
Switch to @jest/globals (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
FloEdelmann authored Apr 10, 2024
1 parent 480759e commit 51a29b6
Show file tree
Hide file tree
Showing 28 changed files with 50 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ updates:
interval: 'daily'
labels:
- 'dependencies'
groups:
jest:
patterns:
- 'jest'
- '@jest/globals'

- package-ecosystem: 'github-actions'
directory: '/'
Expand Down
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ export default typescriptEslint.config(
'jest/no-duplicate-hooks': 'error',
'jest/no-test-return-statement': 'error',
'jest/no-untyped-mock-factory': 'error',
'jest/prefer-called-with': 'warn',
'jest/prefer-called-with': 'error',
'jest/prefer-comparison-matcher': 'warn',
'jest/prefer-equality-matcher': 'warn',
'jest/prefer-expect-resolves': 'warn',
'jest/prefer-hooks-on-top': 'warn',
'jest/prefer-importing-jest-globals': 'error',
'jest/prefer-mock-promise-shorthand': 'error',
'jest/prefer-spy-on': 'warn',
'jest/prefer-strict-equal': 'warn',
Expand Down
10 changes: 9 additions & 1 deletion global.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
import 'jest-extended';
import type CustomMatchers from 'jest-extended';

declare module 'expect' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface -- needed for declaration merging
interface AsymmetricMatchers extends CustomMatchers {}

// eslint-disable-next-line @typescript-eslint/no-empty-interface -- needed for declaration merging
interface Matchers<R> extends CustomMatchers<R> {}
}
12 changes: 1 addition & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"homepage": "https://github.com/FloEdelmann/vue-ts-types",
"devDependencies": {
"@eslint/js": "^9.0.0",
"@types/jest": "^29.5.12",
"@jest/globals": "^29.7.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.2.0",
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/any.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { anyProp } from '../../src/prop-types/any';

describe('anyProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/array.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { arrayProp } from '../../src/prop-types/array';

describe('arrayProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/boolean.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { booleanProp } from '../../src/prop-types/boolean';

describe('booleanProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/function.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { functionProp } from '../../src/prop-types/function';

describe('functionProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/instanceOf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { instanceOfProp } from '../../src/prop-types/instanceOf';

class User {}
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/integer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { integerProp } from '../../src/prop-types/integer';

describe('integerProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/number.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { numberProp } from '../../src/prop-types/number';

describe('numberProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/object.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { objectProp } from '../../src/prop-types/object';

describe('objectProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/oneOf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { oneOfProp } from '../../src/prop-types/oneOf';

describe('oneOfProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/oneOfObjectKeys.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { oneOfObjectKeysProp } from '../../src/prop-types/oneOfObjectKeys';

const options = { a: 'a', b: 'b', c: 'c' };
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/oneOfTypes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { oneOfTypesProp } from '../../src/prop-types/oneOfTypes';

describe('oneOfTypesProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/string.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { stringProp } from '../../src/prop-types/string';

describe('stringProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/symbol.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { symbolProp } from '../../src/prop-types/symbol';

describe('symbolProp().optional', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/prop-types/vueComponent.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { vueComponentProp } from '../../src/prop-types/vueComponent';

describe('vueComponentProp().optional', () => {
Expand Down
15 changes: 10 additions & 5 deletions tests/validators/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { describe, expect, it, jest } from '@jest/globals';
import { vuePropValidator } from '../../src/validators';

describe('vuePropValidator', () => {
const validator1 = jest.fn();
const validator2 = jest.fn();
const validator3 = jest.fn().mockReturnValue('some error message');
const validator4 = jest.fn();
const validator1 = jest.fn<() => string | undefined>();
const validator2 = jest.fn<() => string | undefined>();
const validator3 = jest
.fn<() => string | undefined>()
.mockReturnValue('some error message');
const validator4 = jest.fn<() => string | undefined>();

const warnSpy = jest.spyOn(console, 'warn').mockImplementation();
const warnSpy = jest
.spyOn(console, 'warn')
.mockImplementation(() => undefined);

it('returns undefined if no validator is passed', () => {
expect(vuePropValidator()).toBeUndefined();
Expand Down
1 change: 1 addition & 0 deletions tests/validators/isInstanceOf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { isInstanceOf } from '../../src/validators/isInstanceOf';

describe('isInstanceOf', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/validators/isInteger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { isInteger } from '../../src/validators/isInteger';

describe('isInteger', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/validators/isNegative.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { isNegative } from '../../src/validators/isNegative';

describe('isNegative', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/validators/isNonNegative.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { isNonNegative } from '../../src/validators/isNonNegative';

describe('isNonNegative', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/validators/isNonPositive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { isNonPositive } from '../../src/validators/isNonPositive';

describe('isNonPositive', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/validators/isOneOf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { isOneOf } from '../../src/validators/isOneOf';

describe('isOneOf', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/validators/isPositive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { isPositive } from '../../src/validators/isPositive';

describe('isPositive', () => {
Expand Down
1 change: 1 addition & 0 deletions tests/validators/isSymbol.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from '@jest/globals';
import { isSymbol } from '../../src/validators/isSymbol';

describe('isSymbol', () => {
Expand Down

0 comments on commit 51a29b6

Please sign in to comment.