@@ -57,6 +57,13 @@ describe('Jasmine-Specific Features', () => {
5757 await expect ( tagName ) . toBe ( 'button' )
5858 } )
5959
60+ it ( 'should use withContext on WDIO matcher' , async ( ) => {
61+ const searchButton = await $ ( '.DocSearch-Button' )
62+
63+ await expect ( searchButton ) . withContext ( 'Search button should be visible on the homepage' ) . toBeDisplayed ( )
64+ await expect ( searchButton ) . withContext ( 'Search button should exist on the homepage' ) . toExist ( )
65+ } )
66+
6067 // TODO failing on jasmine.stringContaining not working properly with wdio matchers
6168 xit ( 'should use asymmetric matchers in toHaveAttribute' , async ( ) => {
6269 const docsLink = await $ ( 'a[href="/docs/gettingstarted"]' )
@@ -166,13 +173,51 @@ describe('Jasmine-Specific Features', () => {
166173 } )
167174 } )
168175
169- describe ( 'Expect.withContext usage ' , ( ) => {
170- xit ( 'should provide additional context on failure ' , async ( ) => {
176+ describe ( 'Jasmine core matcher use cases with expect ' , ( ) => {
177+ it ( 'should use all core Jasmine matchers with expect ' , async ( ) => {
171178 const title = await browser . getTitle ( )
179+ const navLinks = await $$ ( 'nav a' )
180+ const count = navLinks . length
181+ const firstLink = navLinks [ 0 ]
182+ const tagName = await firstLink . getTagName ( )
183+ const arr = [ 1 , 2 , 3 ]
184+ const obj = { foo : 'bar' , num : 42 }
172185
173- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
174- // @ts -ignore -- withContext fails tsc, see https://github.com/webdriverio/expect-webdriverio/issues/1407
175- await expect ( title ) . withContext ( 'Checking page title for webdriver.io' ) . toBe ( 'Non-Matching Title' )
186+ // Equality
187+ await expect ( title ) . toEqual ( 'WebdriverIO · Next-gen browser and mobile automation test framework for Node.js | WebdriverIO' )
188+ await expect ( count ) . toBeGreaterThan ( 0 )
189+ await expect ( count ) . toBeLessThan ( 100 )
190+ await expect ( count ) . toBeGreaterThanOrEqual ( 1 )
191+ await expect ( count ) . toBeLessThanOrEqual ( 100 )
192+ await expect ( count ) . toBeCloseTo ( 49 , 3 )
193+ await expect ( count ) . not . toBeNaN ( )
194+ await expect ( tagName ) . toBeDefined ( )
195+ await expect ( tagName ) . not . toBeUndefined ( )
196+ await expect ( tagName ) . toBeTruthy ( )
197+ await expect ( '' ) . toBeFalsy ( )
198+ await expect ( arr ) . toContain ( 2 )
199+ await expect ( arr ) . not . toContain ( 99 )
200+ await expect ( obj ) . toEqual ( jasmine . objectContaining ( { foo : 'bar' } ) )
201+ await expect ( arr ) . toEqual ( jasmine . arrayContaining ( [ 1 , 2 ] ) )
202+ await expect ( title ) . toMatch ( / W e b d r i v e r I O / )
203+ await expect ( title ) . toEqual ( jasmine . stringContaining ( 'WebdriverIO' ) )
204+ await expect ( obj ) . toBeInstanceOf ( Object )
205+ await expect ( Promise . resolve ( 1 ) ) . toBeResolved ( )
206+ await expect ( Promise . reject ( 'fail' ) ) . toBeRejected ( )
207+
208+ // @ts -expect-error -- toThrowError is not recognized properly to fix one day
209+ await expect ( Promise . resolve ( 42 ) ) . toBeResolvedTo ( 42 )
210+ // @ts -expect-error -- toBeRejectedWith is not recognized properly to fix one day
211+ await expect ( Promise . reject ( 'fail' ) ) . toBeRejectedWith ( 'fail' )
212+ // @ts -expect-error -- toThrowError is not recognized properly to fix one day
213+ await expect ( ( ) => { throw new Error ( 'fail' ) } ) . toThrowError ( 'fail' )
214+
215+ // withContext with various matchers
216+ await expect ( title ) . withContext ( 'Title should contain WebdriverIO' ) . toMatch ( / W e b d r i v e r I O / )
217+ await expect ( arr ) . withContext ( 'Array should contain 2' ) . toContain ( 2 )
218+ await expect ( obj ) . withContext ( 'Object should have foo' ) . toEqual ( jasmine . objectContaining ( { foo : 'bar' } ) )
176219 } )
220+
221+
177222 } )
178223} )
0 commit comments