Skip to content

Latest commit

 

History

History
52 lines (38 loc) · 1.45 KB

contentMatches.md

File metadata and controls

52 lines (38 loc) · 1.45 KB

.contentMatches(matcher) => Boolean

Returns whether or not the page text matches the given matcher

Arguments

  1. matcher (RegExp or String): If given a RegExp, this is used to match against the page content. If given a String, a RegExp is created using the String as a pattern. This created RegExp is used to match against the page content. It is important to note that this created RegExp is case sensitive.

Returns

true or false depending on whether the RegExp matcher matches against the return value of .content() => String.

Related Methods

Example in Jest

import React from 'react'
import Page from 'react-page-object'

const App = () => <h1>My App</h1>

describe('contentMatches', () => {
  let page

  beforeEach(() => {
    page = new Page(<App />)
  })

  afterEach(() => {
    page.destroy()
  })

  it('returns true if content matches - RegExp given', () => {
    expect(page.contentMatches(/My App/)).toBe(true)
  })

  it('returns true if content matches - string given', () => {
    expect(page.contentMatches('My App')).toBe(true)
  })

  it('returns false if content does not match', () => {
    expect(page.contentMatches(/should not match/)).toBe(false)
  })
})