Skip to content

Commit

Permalink
Adding default trim for toHaveText and toHaveTextContaining (#398)
Browse files Browse the repository at this point in the history
* Adding default trim for toHaveText and toHaveTextContaining

* Adding trim as false for test -> 'not - failure (with wait)'
  • Loading branch information
mathew-jithin authored May 14, 2021
1 parent 5373914 commit 7992ffe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const compareNumbers = (actual: number, gte: number, lte: number, eq?: number):
return actual >= gte
}

export const compareText = (actual: string, expected: string, { ignoreCase = false, trim = false, containing = false }) => {
export const compareText = (actual: string, expected: string, { ignoreCase = false, trim = true, containing = false }) => {
if (typeof actual !== 'string') {
return {
value: actual,
Expand Down
14 changes: 7 additions & 7 deletions test/matchers/browserMatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('browser matchers', () => {
return validText
}

const result = await fn.call({}, browser, validText)
const result = await fn.call({}, browser, validText, { trim: false })
expect(result.pass).toBe(true)
expect(browser._attempts).toBe(0)
})
Expand All @@ -31,7 +31,7 @@ describe('browser matchers', () => {
throw new Error('some error')
}

const result = await fn.call({}, browser, validText)
const result = await fn.call({}, browser, validText, { trim: false })
expect(result.pass).toBe(false)
})

Expand All @@ -42,7 +42,7 @@ describe('browser matchers', () => {
return validText
}

const result = await fn.call({}, browser, validText)
const result = await fn.call({}, browser, validText, { trim: false })
expect(result.pass).toBe(true)
expect(browser._attempts).toBe(1)
})
Expand All @@ -54,7 +54,7 @@ describe('browser matchers', () => {
return wrongText
}

const result = await fn.call({}, browser, validText, { wait: 0 })
const result = await fn.call({}, browser, validText, { wait: 0, trim: false })
expect(result.pass).toBe(false)
expect(browser._attempts).toBe(1)
})
Expand All @@ -66,14 +66,14 @@ describe('browser matchers', () => {
return validText
}

const result = await fn.call({}, browser, validText, { wait: 0 })
const result = await fn.call({}, browser, validText, { wait: 0, trim: false })

expect(result.pass).toBe(true)
expect(browser._attempts).toBe(1)
})

test('not - failure', async () => {
const result = await fn.call({ isNot: true }, browser, validText, { wait: 0 })
const result = await fn.call({ isNot: true }, browser, validText, { wait: 0, trim: false })

expect(getExpectMessage(result.message())).toContain('not')
expect(getExpected(result.message())).toContain('not')
Expand All @@ -95,7 +95,7 @@ describe('browser matchers', () => {
})

test('not - failure (with wait)', async () => {
const result = await fn.call({ isNot: true }, browser, validText, { wait: 1 })
const result = await fn.call({ isNot: true }, browser, validText, { wait: 1, trim: false })

expect(getExpectMessage(result.message())).toContain('not')
expect(getExpected(result.message())).toContain('not')
Expand Down
8 changes: 6 additions & 2 deletions test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ describe('utils', () => {
})

test('trim', () => {
expect(compareText(' foo ', 'foo', { trim: true }).result).toBe(true)
expect(compareText(' foo ', 'foo', {}).result).toBe(true)
})

test('without trim', () => {
expect(compareText(' foo ', 'foo ', { trim: false }).result).toBe(false)
})

test('ignoreCase', () => {
expect(compareText(' FOO ', 'foo', { trim: true, ignoreCase: true }).result).toBe(true)
expect(compareText(' FOO ', 'foo', { ignoreCase: true }).result).toBe(true)
})

test('containing', () => {
Expand Down

0 comments on commit 7992ffe

Please sign in to comment.