Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cypress-jest-adapter

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-jest-adapter

Add jest style expect on top of chai to Cypress

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
increased by1.52%
Maintainers
1
Weekly downloads
 
Created
Source

Jest assertions for Cypress

cypress-jest-adapter provides set of custom assertions using jest assertion style to Cypress expect command

Allow to use jest style commands to do assertion:

expect(1).toEqual(1)

besides chai assertions style of

expect(1).to.be.equal(1)

Also, can do assertions for jQuery elements return from cy.get() function directly:

expect($el).toHaveId
expect($el).toHaveClass

Example

Installation

yarn add cypress-jest-adapter

or

npm install --save cypress-jest-adapter

Add cypress-jest-adapter to cypress support/index.js file

import 'cypress-jest-adapter'

Assertions

Available assertions:

Value assertion (using jest matchers)
methodassertions
toBeexpect(sth).toBe
toBeCloseToexpect(sth).toBeCloseTo
toBeDefinedexpect(sth).toBeDefined
toBeFalsyexpect(sth).toBeFalsy
toBeGreaterThanexpect(sth).toBeGreaterThan
toBeGreaterThanOrEqualexpect(sth).toBeGreaterThanOrEqual
toBeLessThanexpect(sth).toBeLessThan
toBeLessThanOrEqualexpect(sth).toBeLessThanOrEqual
toBeInstanceOfexpect(sth).toBeInstanceOf
toBeNullexpect(sth).toBeNull
toBeTruthyexpect(sth).toBeTruthy
toBeUndefinedexpect(sth).toBeUndefined
toBeNaNexpect(sth).toBeNaN
toContainexpect(sth).toContain
toContainEqualexpect(sth).toContainEqual
toEqualexpect(sth).toEqual
toHaveLengthexpect(sth).toHaveLength
toMatchexpect(sth).toMatch
toMatchObjectexpect(sth).toMatchObject
toHavePropertyexpect(sth).toHaveProperty
toStrictEqualexpect(sth).toStrictEqual
toThrowexpect(sth).toThrow
Promise handlers
methodassertions
resolvesexpect(sth).resolves.toBe(sth)
rejectsexpect(sth).rejects.toThrow(error)
Mock assertions (using chai, chai-sinon and jest equal assertion)
methodassertions
toHaveBeenCalledexpect(spy).toHaveBeenCalled
toHaveBeenCalledTimesexpect(spy).toHaveBeenCalledTimes
toHaveBeenCalledWithexpect(spy).toHaveBeenCalledWith
toHaveBeenNthCalledWithexpect(spy).toHaveBeenNthCalledWith
toHaveReturnedexpect(spy).toHaveReturned
toHaveReturnedTimesexpect(spy).toHaveReturnedTimes
toHaveReturnedWithexpect(spy).toHaveReturnedWith
toHaveLastReturnedWithexpect(spy).toHaveLastReturnedWith
toHaveNthReturnedWithexpect(spy).toHaveNthReturnedWith
Assumptions
methodassertions
anythingexpect(sth).toBe(expect.anything())
anyexpect(sth).toBe(expect.any())
arrayContainingexpect(sth).toBe(expect.arrayContaining())
objectContainingexpect(sth).toBe(expect.objectContaining())
stringContainingexpect(sth).toBe(expect.stringContaining())
stringMatchingexpect(sth).toBe(expect.stringMatching())
Not implement Jest functions
method
toMatchSnapshot
toMatchInlineSnapshot
toThrowErrorMatchingSnapshot
toThrowErrorMatchingInlineSnapshot
assertions
hasAsertions

For detailed usages, go to jest expect documentation

Jest-Jquery assertions
methodassertionschai-jquery equivalent
toHaveAttrexpect($ele).toHaveAttr(attribute: string, value?: string)to.have.attr
toHavePropexpect($ele).toHaveProp(property: string, value?: string)to.have.prop
toHaveCssexpect($ele).toHaveCss(css: string/object, value?: string)to.have.css
toHaveDataexpect($ele).toHaveData(key: string, data?: string)to.have.data
toHaveClassexpect($ele).toHaveClass(className: string)to.have.class
toHaveIdexpect($ele).toHaveId(id: string)to.have.id
toHaveHtmlexpect($ele).toHaveHtml(html: string)to.have.html
toHaveTextexpect($ele).toHaveText(text: string)to.have.text
toHaveValueexpect($ele).toHaveValue(value: string)to.have.value
toBeVisibleexpect($ele).toBeVisible()to.be.visible
toBeHiddenexpect($ele).toBeHidden()to.be.hidden
toBeSelectedexpect($ele).toBeSelected()to.be.selected
toBeCheckedexpect($ele).toBeChecked()to.be.checked
toBeEnabledexpect($ele).toBeEnabled()to.be.enabled
toBeDisabledexpect($ele).toBeDisabled()to.be.disabled
toBeEmptyexpect($ele).toBeEmpty()to.be.empty
toExistexpect($ele).toExist()to.exist
toBeMatchedByexpect($ele).toBeMatchedBy(selector: string)to.match
toMatchSelectorexpect($ele).toMatchSelector(selector: string)to.match
toContainTextexpect($ele).toContainText(text: string)to.contain
toHaveDescendantexpect($ele).toHaveDescendant(selector: string)to.have.descendants
toHaveDescendantWithTextexpect($ele).toHaveDescendantWithText(selector: string, text: string)
toHaveQuantityexpect($ele).toHaveQuantity(length: number)
toHaveTagexpect($ele).toHaveTag(tag: string)
toBeFocusedexpect($ele).toBeFocused()
Used library:
  • jest expect package for value assertions
  • cypress available chai-sinon package for mock assertions
  • chai assert function to provide results to cypress
  • jest-jquery-matchers for jest-jquery assertions

License

MIT

Keywords

FAQs

Package last updated on 26 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc