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 · Fixed by #3787
Closed

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

Akxe opened this issue Oct 9, 2018 · 8 comments · Fixed by #3787
Assignees

Comments

@Akxe
Copy link

Akxe 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
Copy link
Contributor

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
Copy link
Author

Akxe commented Oct 9, 2018 via email

@Manishku99251
Copy link

Manishku99251 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
Copy link
Author

Akxe commented Mar 9, 2019

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

@Manishku99251
Copy link

Manishku99251 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
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels Mar 21, 2019
@jennifer-shehane
Copy link
Member

jennifer-shehane 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
Copy link
Contributor

cypress-bot bot 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 cypress-bot bot removed the stage: needs review The PR code is done & tested, needs review label Mar 25, 2019
@cypress-bot
Copy link
Contributor

cypress-bot bot 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants