Skip to content

Commit c6304bb

Browse files
committed
Review some TODOs
1 parent bcf5a31 commit c6304bb

4 files changed

Lines changed: 20 additions & 48 deletions

File tree

test-types/jest-@jest_global/types-jest.test.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ describe('type assertions', async () => {
4646

4747
// @ts-expect-error
4848
await expect(browser).toHaveUrl(6)
49-
//// @ts-expect-error TODO dprevost can we make the below fail?
50-
// await expect(browser).toHaveUrl(expect.objectContaining({}))
5149
})
5250

5351
it('should have ts errors when actual is not a Browser element', async () => {
@@ -538,7 +536,7 @@ describe('type assertions', async () => {
538536

539537
it('should expect a Promise of type', async () => {
540538
const expectPromiseBoolean1: ExpectWebdriverIO.MatchersAndInverse<void, Promise<boolean>> = expect(booleanPromise)
541-
const expectPromiseBoolean2: jest.Matchers<void, Promise<boolean>> = expect(booleanPromise).not
539+
const expectPromiseBoolean2: ExpectWebdriverIO.Matchers<void, Promise<boolean>> = expect(booleanPromise).not
542540

543541
// @ts-expect-error
544542
const expectPromiseBoolean3: jest.JestMatchers<boolean> = expect(booleanPromise)
@@ -589,11 +587,6 @@ describe('type assertions', async () => {
589587
response: { success: true },
590588
})
591589

592-
// TODO dprevost: Asymmetric matcher is not defined on the entire object in the .d.ts file, it is a bug?
593-
// expectPromiseVoid = expect(promiseNetworkMock).toBeRequestedWith(expect.objectContaining({
594-
// response: { success: true }, // [optional] object | function | custom matcher
595-
// }))
596-
597590
expectPromiseVoid = expect(promiseNetworkMock).toBeRequestedWith({
598591
url: expect.stringContaining('test'),
599592
method: 'POST',
@@ -681,22 +674,14 @@ describe('type assertions', async () => {
681674
expect.not.arrayContaining(['WebdriverIO', 'Test'])
682675
expect.not.arrayOf(expect.stringContaining('WebdriverIO'))
683676

684-
//@ts-expect-error
685-
expect.not.anything()
686-
//@ts-expect-error
687-
expect.not.any(Function)
688-
//@ts-expect-error
689-
expect.not.any(Number)
690-
//@ts-expect-error
691-
expect.not.any(Boolean)
692-
//@ts-expect-error
693-
expect.not.any(String)
694-
//@ts-expect-error
695-
expect.not.any(Symbol)
696-
//@ts-expect-error
697-
expect.not.any(Date)
698-
//@ts-expect-error
699-
expect.not.any(Error)
677+
// expect.not.anything()
678+
// expect.not.any(Function)
679+
// expect.not.any(Number)
680+
// expect.not.any(Boolean)
681+
// expect.not.any(String)
682+
// expect.not.any(Symbol)
683+
// expect.not.any(Date)
684+
// expect.not.any(Error)
700685
})
701686

702687
describe('Soft Assertions', async () => {
@@ -733,13 +718,13 @@ describe('type assertions', async () => {
733718
})
734719

735720
it('should support chainable element', async () => {
736-
const expectElement: WdioCustomMatchers<void, WebdriverIO.Element> = expect.soft(element)
737-
const expectElementChainable: WdioCustomMatchers<void, typeof chainableElement> = expect.soft(chainableElement)
721+
const expectElement: ExpectWebdriverIO.MatchersAndInverse<void, WebdriverIO.Element> = expect.soft(element)
722+
const expectElementChainable: ExpectWebdriverIO.MatchersAndInverse<void, typeof chainableElement> = expect.soft(chainableElement)
738723

739724
// @ts-expect-error
740-
const expectElement2: WdioCustomMatchers<Promise<void>, WebdriverIO.Element> = expect.soft(element)
725+
const expectElement2: ExpectWebdriverIO.MatchersAndInverse<Promise<void>, WebdriverIO.Element> = expect.soft(element)
741726
// @ts-expect-error
742-
const expectElementChainable2: WdioCustomMatchers<Promise<void>, typeof chainableElement> = expect.soft(chainableElement)
727+
const expectElementChainable2: ExpectWebdriverIO.MatchersAndInverse<Promise<void>, typeof chainableElement> = expect.soft(chainableElement)
743728
})
744729

745730
it('should support chainable element with wdio Matchers', async () => {

test-types/jest-@types_jest/types-jest.test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ describe('type assertions', async () => {
4343

4444
// @ts-expect-error
4545
await expect(browser).toHaveUrl(6)
46-
//// @ts-expect-error TODO dprevost can we make the below fail?
47-
// await expect(browser).toHaveUrl(expect.objectContaining({}))
4846
})
4947

5048
it('should have ts errors when actual is not a Browser element', async () => {
@@ -720,13 +718,13 @@ describe('type assertions', async () => {
720718
})
721719

722720
it('should support chainable element', async () => {
723-
const expectElement: WdioCustomMatchers<void, WebdriverIO.Element> = expect.soft(element)
724-
const expectElementChainable: WdioCustomMatchers<void, typeof chainableElement> = expect.soft(chainableElement)
721+
const expectElement: ExpectWebdriverIO.MatchersAndInverse<void, WebdriverIO.Element> = expect.soft(element)
722+
const expectElementChainable: ExpectWebdriverIO.MatchersAndInverse<void, typeof chainableElement> = expect.soft(chainableElement)
725723

726724
// @ts-expect-error
727-
const expectElement2: WdioCustomMatchers<Promise<void>, WebdriverIO.Element> = expect.soft(element)
725+
const expectElement2: ExpectWebdriverIO.MatchersAndInverse<Promise<void>, WebdriverIO.Element> = expect.soft(element)
728726
// @ts-expect-error
729-
const expectElementChainable2: WdioCustomMatchers<Promise<void>, typeof chainableElement> = expect.soft(chainableElement)
727+
const expectElementChainable2: ExpectWebdriverIO.MatchersAndInverse<Promise<void>, typeof chainableElement> = expect.soft(chainableElement)
730728
})
731729

732730
it('should support chainable element with wdio Matchers', async () => {

test-types/mocha/types-mocha.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ describe('type assertions', () => {
3737

3838
// @ts-expect-error
3939
await expect(browser).toHaveUrl(6)
40-
//// @ts-expect-error TODO dprevost can we make the below fail?
41-
// await expect(browser).toHaveUrl(expect.objectContaining({}))
4240
})
4341

4442
it('should have ts errors when actual is not a Browser element', async () => {
@@ -581,11 +579,6 @@ describe('type assertions', () => {
581579
response: { success: true },
582580
})
583581

584-
// TODO dprevost: Asymmetric matcher is not defined on the entire object in the .d.ts file, it is a bug?
585-
// expectPromiseVoid = expect(promiseNetworkMock).toBeRequestedWith(expect.objectContaining({
586-
// response: { success: true }, // [optional] object | function | custom matcher
587-
// }))
588-
589582
expectPromiseVoid = expect(promiseNetworkMock).toBeRequestedWith({
590583
url: expect.stringContaining('test'),
591584
method: 'POST',
@@ -673,7 +666,7 @@ describe('type assertions', () => {
673666
expect.not.arrayContaining(['WebdriverIO', 'Test'])
674667
expect.not.arrayOf(expect.stringContaining('WebdriverIO'))
675668

676-
// TODO dprevost: Should we support these?
669+
// TODO dprevost to review
677670
// expect.not.anything()
678671
// expect.not.any(Function)
679672
// expect.not.any(Number)

types/expect-webdriverio.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type ExpectLibAsymmetricMatchers = import('expect').AsymmetricMatchers
1515
type ExpectLibAsymmetricMatcher<T> = import('expect').AsymmetricMatcher<T>
1616
type ExpectLibMatchers<R extends void | Promise<void>, T> = import('expect').Matchers<R, T>
1717
type ExpectLibExpect = import('expect').Expect
18-
type ExpectLibInverse<Matcher> = import('expect').Inverse<Matcher>
18+
type ExpectLibInverse<Matchers> = import('expect').Inverse<Matchers>
1919

2020
// TODO dprevost: a suggestion would be to move any code outside of the namespace to separate types.ts file, so that we can import the types.
2121

@@ -375,8 +375,6 @@ interface WdioElementArrayOnlyMatchers<_R, ActualT = unknown> {
375375
* ⚠️ these matchers overload the similar matchers from jest-expect library.
376376
* Therefore, they also need to be redefined in the jest.d.ts file so correctly overload the matchers from the Jest namespace.
377377
* @see jest.d.ts
378-
*
379-
* TODO dprevost: Review for better typings...
380378
*/
381379
interface WdioJestOverloadedMatchers<_R, ActualT> {
382380
/**
@@ -475,7 +473,7 @@ declare namespace ExpectWebdriverIO {
475473
* `AsymmetricMatchers` and `Inverse<AsymmetricMatchers>` needs to be defined and be before the `expect` library Expect (aka `WdioExpect`).
476474
* The above allows to have custom asymmetric matchers under the `ExpectWebdriverIO` namespace.
477475
*/
478-
interface Expect extends ExpectWebdriverIO.AsymmetricMatchers, ExpectLibInverse<Omit<ExpectWebdriverIO.AsymmetricMatchers, 'any' | 'anything'>>, WdioExpect {
476+
interface Expect extends ExpectWebdriverIO.AsymmetricMatchers, ExpectLibInverse<Omit<ExpectWebdriverIO.AsymmetricMatchers, 'anything' | 'any'>>, WdioExpect {
479477
/**
480478
* The `expect` function is used every time you want to test a value.
481479
* You will rarely call `expect` by itself.
@@ -717,8 +715,6 @@ declare namespace ExpectWebdriverIO {
717715
* Allow to partially matches value. Same as asymmetric matcher in jest.
718716
* Some properties are omitted for the type check to work correctly.
719717
*/
720-
// TODO dprevost: verify if we do breaking changes on this PartialMatcher, since before it was the AsymmetricMatcher interface used everywhere.
721-
// TODO dprevost: verify if we should restrict to possible asymmetric matchers used!
722718
type PartialMatcher<T> = Omit<ExpectLibAsymmetricMatcher<T>, 'sample' | 'inverse' | '$$typeof'>
723719
}
724720

0 commit comments

Comments
 (0)