Skip to content

Commit eeae2de

Browse files
committed
Code review + docs
1 parent a57306c commit eeae2de

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

docs/API.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ it('product page smoke', async () => {
1414
// These won't throw immediately if they fail
1515
await expect.soft(await $('h1').getText()).toEqual('Basketball Shoes');
1616
await expect.soft(await $('#price').getText()).toMatch(/\d+/);
17+
18+
// Also work with basic matcher
19+
const h1Text = await $('h1').getText()
20+
expect.soft(h1Text).toEqual('Basketball Shoes');
1721

1822
// Regular assertions still throw immediately
1923
await expect(await $('.add-to-cart').isClickable()).toBe(true);
@@ -75,7 +79,7 @@ export const config = {
7579
// ...
7680
services: [
7781
// ...other services
78-
[SoftAssertionService]
82+
[SoftAssertionService, {}]
7983
],
8084
// ...
8185
}

test/softAssertions.test.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,42 +55,29 @@ describe('Soft Assertions', () => {
5555
await Promise.all([elementSoftToHaveText, elementsSoftToHaveText, elementsSoftNotToHaveText])
5656
})
5757

58-
it('should handle non-promises properly', () => {
58+
it('should handle non-promises matchers properly by not using promises', () => {
5959
const softService = SoftAssertService.getInstance()
6060
softService.setCurrentTest('non-promise-1', 'test name', 'test file')
6161

62+
// Base line on Jest 'expect' library
6263
expect(expectLib(true).toBe(true)).toBeUndefined()
6364
expect(expectLib(true).toBe).toBeInstanceOf(Function)
6465
expect(expectLib(true).toBe(true)).not.toBeInstanceOf(Promise)
6566
expect(expectLib(true).not.toBe(false)).not.toBeInstanceOf(Promise)
6667

68+
// wdio expect
6769
expect(expectWdio(true).toBe(true)).toBeUndefined()
6870
expect(expectWdio(true).toBe).toBeInstanceOf(Function)
6971
expect(expectWdio(true).toBe(true)).not.toBeInstanceOf(Promise)
7072
expect(expectWdio(true).not.toBe(false)).not.toBeInstanceOf(Promise)
7173

74+
// wdio expect.soft
7275
expect(expectWdio.soft(true).toBe(true)).toBeUndefined()
7376
expect(expectWdio.soft(true).toBe).toBeInstanceOf(Function)
7477
expect(expectWdio.soft(true).toBe).not.toBeInstanceOf(Promise)
7578
expect(expectWdio.soft(true).not.toBe(false)).not.toBeInstanceOf(Promise)
7679
})
7780

78-
it.for([
79-
'',
80-
2,
81-
[],
82-
])('should handle non-promises and return a non-promise target to have the correct runtime type', (actualPromise) => {
83-
const softService = SoftAssertService.getInstance()
84-
softService.setCurrentTest('non-promise-2', 'test name', 'test file')
85-
86-
const wdioExpect = expectWdio(actualPromise)
87-
expect(wdioExpect).not.toBeInstanceOf(Promise)
88-
89-
const softExpect = expectWdio.soft(actualPromise)
90-
expect(softExpect).toBeInstanceOf(Object)
91-
expect(softExpect).not.toBeInstanceOf(Promise)
92-
})
93-
9481
it('should not throw immediately on failure', async () => {
9582
const softService = SoftAssertService.getInstance()
9683
softService.setCurrentTest('test-1', 'test name', 'test file')
@@ -213,7 +200,7 @@ describe('Soft Assertions', () => {
213200
expect(failures[0].matcherName).toBe('not.toEqual')
214201
})
215202

216-
it.skip('not - should support basic matcher success', async () => {
203+
it('not - should support basic matcher success', async () => {
217204
const softService = SoftAssertService.getInstance()
218205
softService.setCurrentTest('test-10', 'test name', 'test file')
219206

0 commit comments

Comments
 (0)