Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type definition for 'match' - removes 'string', should be 'RegExp' #2578

Closed
Akxe opened this issue Oct 9, 2018 · 8 comments

Comments

5 participants
@Akxe
Copy link

commented Oct 9, 2018

Current behaviour:

'match' requires its argument be a 'RegExp'. You passed 'https://example.com'.

Desired behaviour:

Since in type anotation is as fallow:

/**
 * Asserts that the target matches the given regular expression `re`.
 * @example
 *    cy.wrap('foobar').should('match', /^foo/)
 * @see http://chaijs.com/api/bdd/#method_match
 * @see https://on.cypress.io/assertions
 */
(chainer: 'match', value: string | RegExp): Chainable<Subject>

I would assume it would take string. Since it is match I thought it would use String.match function...

Steps to reproduce:

context('test', () => {
	it('test', () => {
		cy.wrap('hello world').should('match', 'wolrd')
	})
})

Versions

Cypress: 3.1.0
OS: Windows 10
Browser: Chrome 69.x.x

@chrisbreiding

This comment has been minimized.

Copy link
Collaborator

commented Oct 9, 2018

Looks like we have the type annotation wrong.

This is part of chai and is documented to only accept a RegExp. This follows the String.prototype.match signature.

For matching a substring, you can use include instead:

cy.wrap('hello world').should('include', 'wolrd')
@Akxe

This comment has been minimized.

Copy link
Author

commented Oct 9, 2018

@Manishku99251

This comment has been minimized.

Copy link

commented Mar 9, 2019

Hi I am learning Cypress and new to it just wanted to know how can I achieve the Following
: want to check the font-family value of the button but match is expexcting a Regexp

it('finds the Submit Button and Submits it', function(){

      cy.get('input[type="submit"]').should('have.css','font-family').and('match','inherit')

     cy.get('input[type="submit"]').click().then((submitobj)=>{

         //cy.get(obj).should('have.value')
         expect(submitobj).to.have.value('LOGIN')
     })

  })
@Akxe

This comment has been minimized.

Copy link
Author

commented Mar 9, 2019

Either use .and('match', /inherit/), or I think there is contain keyword.

@Manishku99251

This comment has been minimized.

Copy link

commented Mar 15, 2019

@Akxe I am still unable to make it work could you please give an example or something. my requirement is like to match something with the url? eg. cy.url().should('match','/adfs/ls/')

@jennifer-shehane jennifer-shehane changed the title 'match' requires its argument be a 'RegExp' Wrong type definition for 'match' - removes 'string', should be 'RegExp' Mar 21, 2019

@jennifer-shehane

This comment has been minimized.

Copy link
Member

commented Mar 21, 2019

@Manishku99251 This annotation for using cypress is correct - cy.url().should('match','/login/'), I would suggest using a regexp checker to determine how to write the regexp against what you want to check.

@cypress-bot

This comment has been minimized.

Copy link

commented Mar 25, 2019

The code for this is done in cypress-io/cypress#3787, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot

This comment has been minimized.

Copy link

commented May 17, 2019

Released in 3.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.