11import { vi , test , describe , expect } from 'vitest'
22import { browser } from '@wdio/globals'
33
4- import { getExpectMessage , getReceived , matcherNameToString , getExpected } from '../__fixtures__/utils.js'
4+ import { matcherNameToString } from '../__fixtures__/utils.js'
55import * as Matchers from '../../src/matchers.js'
66
77vi . mock ( '@wdio/globals' )
@@ -91,12 +91,19 @@ describe('browser matchers', () => {
9191 } )
9292
9393 test ( 'not - failure' , async ( ) => {
94- const result = await fn . call ( { isNot : true } , browser , validText , { wait : 0 , trim : false } ) as ExpectWebdriverIO . AssertionResult
94+ // @ts -expect-error mock feature
95+ browser . _value = function ( ) : string {
96+ return validText
97+ }
9598
96- expect ( getExpectMessage ( result . message ( ) ) ) . toContain ( 'not' )
97- expect ( getExpected ( result . message ( ) ) ) . toContain ( 'not' )
99+ const result = await fn . call ( { isNot : true } , browser , validText , { wait : 0 , trim : false } ) as ExpectWebdriverIO . AssertionResult
98100
99101 expect ( result . pass ) . toBe ( false )
102+ expect ( result . message ( ) ) . toEqual ( `\
103+ Expect window not ${ matcherNameToString ( name ) }
104+
105+ Expected [not]: " Valid Text "
106+ Received : " Valid Text "` )
100107 } )
101108
102109 test ( 'not - success' , async ( ) => {
@@ -106,10 +113,6 @@ describe('browser matchers', () => {
106113 }
107114 const result = await fn . call ( { isNot : true } , browser , validText , { wait : 0 } ) as ExpectWebdriverIO . AssertionResult
108115
109- expect ( getExpectMessage ( result . message ( ) ) ) . toContain ( 'not' )
110- expect ( getExpected ( result . message ( ) ) ) . toContain ( 'Valid' )
111- expect ( getReceived ( result . message ( ) ) ) . toContain ( 'Wrong' )
112-
113116 expect ( result . pass ) . toBe ( true )
114117 } )
115118
@@ -118,10 +121,12 @@ describe('browser matchers', () => {
118121 delete browser . _value
119122 const result = await fn . call ( { isNot : true } , browser , validText , { wait : 1 , trim : false } ) as ExpectWebdriverIO . AssertionResult
120123
121- expect ( getExpectMessage ( result . message ( ) ) ) . toContain ( 'not' )
122- expect ( getExpected ( result . message ( ) ) ) . toContain ( 'not' )
123-
124124 expect ( result . pass ) . toBe ( false )
125+ expect ( result . message ( ) ) . toEqual ( `\
126+ Expect window not ${ matcherNameToString ( name ) }
127+
128+ Expected [not]: " Valid Text "
129+ Received : " Valid Text "` )
125130 } )
126131
127132 test ( 'not - success (with wait)' , async ( ) => {
@@ -131,16 +136,23 @@ describe('browser matchers', () => {
131136 }
132137 const result = await fn . call ( { isNot : true } , browser , validText , { wait : 1 } ) as ExpectWebdriverIO . AssertionResult
133138
134- expect ( getExpectMessage ( result . message ( ) ) ) . toContain ( 'not' )
135- expect ( getExpected ( result . message ( ) ) ) . toContain ( 'Valid' )
136- expect ( getReceived ( result . message ( ) ) ) . toContain ( 'Wrong' )
137-
138139 expect ( result . pass ) . toBe ( true )
139140 } )
140141
141142 test ( 'message' , async ( ) => {
143+ // @ts -expect-error mock feature
144+ browser . _value = function ( ) : string {
145+ return wrongText
146+ }
147+
142148 const result = await fn . call ( { } , browser ) as ExpectWebdriverIO . AssertionResult
143- expect ( getExpectMessage ( result . message ( ) ) ) . toContain ( matcherNameToString ( name ) )
149+
150+ expect ( result . pass ) . toBe ( false )
151+ expect ( result . message ( ) ) . toEqual ( `\
152+ Expect window ${ matcherNameToString ( name ) }
153+
154+ Expected: undefined
155+ Received: " Wrong Text "` )
144156 } )
145157 } )
146158 } )
0 commit comments