From 7dafc33abddacad1c4f9e41f41ea919b4d797d61 Mon Sep 17 00:00:00 2001 From: du Date: Sun, 1 Aug 2021 21:22:23 +0800 Subject: [PATCH] refactor: transform test/utils to ts --- .../{Subscription.spec.js => Subscription.spec.ts} | 12 +++++++----- .../{isPlainObject.spec.js => isPlainObject.spec.ts} | 7 ++----- .../{shallowEqual.spec.js => shallowEqual.spec.ts} | 0 3 files changed, 9 insertions(+), 10 deletions(-) rename test/utils/{Subscription.spec.js => Subscription.spec.ts} (81%) rename test/utils/{isPlainObject.spec.js => isPlainObject.spec.ts} (93%) rename test/utils/{shallowEqual.spec.js => shallowEqual.spec.ts} (100%) diff --git a/test/utils/Subscription.spec.js b/test/utils/Subscription.spec.ts similarity index 81% rename from test/utils/Subscription.spec.js rename to test/utils/Subscription.spec.ts index 0cf0d4328..b1f58340f 100644 --- a/test/utils/Subscription.spec.js +++ b/test/utils/Subscription.spec.ts @@ -1,20 +1,22 @@ import { createSubscription } from '../../src/utils/Subscription' +import type { Subscription } from '../../src/utils/Subscription' +import type { Store } from 'redux' describe('Subscription', () => { - let notifications - let store - let parent + let notifications: string[] + let store: Store + let parent: Subscription beforeEach(() => { notifications = [] - store = { subscribe: () => jest.fn() } + store = { subscribe: () => jest.fn() } as unknown as Store parent = createSubscription(store) parent.onStateChange = () => {} parent.trySubscribe() }) - function subscribeChild(name) { + function subscribeChild(name: string) { const child = createSubscription(store, parent) child.onStateChange = () => notifications.push(name) child.trySubscribe() diff --git a/test/utils/isPlainObject.spec.js b/test/utils/isPlainObject.spec.ts similarity index 93% rename from test/utils/isPlainObject.spec.js rename to test/utils/isPlainObject.spec.ts index 0846c0708..283a0f829 100644 --- a/test/utils/isPlainObject.spec.js +++ b/test/utils/isPlainObject.spec.ts @@ -1,12 +1,8 @@ import isPlainObject from '../../src/utils/isPlainObject' import vm from 'vm' - +class Test {} describe('isPlainObject', () => { it('returns true only if plain object', () => { - function Test() { - this.prop = 1 - } - const sandbox = { fromAnotherRealm: false } vm.runInNewContext('fromAnotherRealm = {}', sandbox) @@ -15,6 +11,7 @@ describe('isPlainObject', () => { expect(isPlainObject(new Date())).toBe(false) expect(isPlainObject([1, 2, 3])).toBe(false) expect(isPlainObject(null)).toBe(false) + //@ts-expect-error expect(isPlainObject()).toBe(false) expect(isPlainObject({ x: 1, y: 2 })).toBe(true) expect(isPlainObject(Object.create(null))).toBe(true) diff --git a/test/utils/shallowEqual.spec.js b/test/utils/shallowEqual.spec.ts similarity index 100% rename from test/utils/shallowEqual.spec.js rename to test/utils/shallowEqual.spec.ts