Using Cucumber.js with Jest

I use Jest for my unit tests, and I'm going into the Cucumber.js integration process to run specifications written in Gherkin.

Everything is set up for me and it works, but I ran into one problem: how can I use Jest expect? I could use it chai, but I would like the syntax to expectmatch between my unit tests and my step definitions (I don't want to.equalin my step definitions and toEqualin my unit tests).

How can i do this? After some digging, Jest seems to rely on the expectnpm package . I could explicitly depend on this package in mine package.json, but I would rather use my existing Jest dependency. It may not be possible, but I hope so.

Another option would be to somehow fulfill the Gherkin specifications with the Jest tester. I would be open to this option. I am currently launching them, calling cucumber.jsseparately from my tester Jest.

+4
source share
1 answer

expect - . , . ( babel): gherkin-jest

, DOM- jest:

Feature: Using feature files in jest and cucumber
  As a developer
  I want to write tests in cucumber and jest
  So that businesspeople understand tests and I can test React

  Scenario: Emoji toggles upon checking and unchecking the checkbox
    Given I did not check the checkbox, so the label is "😭"
    When I check the box and the emoji toggles to be "😎"


import {cucumber as c} from 'gherkin-jest'
import React from 'react'
import {mount} from 'enzyme'
import {Checkbox} from '../src/components'

c.defineCreateWorld(() => ({
  checkbox:null
}))

c.defineRule('I did not check the checkbox so the label is {string}', (world, off) => {
  world.checkbox = mount(<Checkbox labelOff={off} />)
  expect(world.checkbox.text()).toBe(off)
})


c.defineRule('I checked the box and the emoji toggles to be {string}', (world, on) =>{
  world.checkbox = mount(<Checkbox labelOn={on}/>)
  world.checkbox.find('TouchableOpacity').props().onPress()
  expect(world.checkbox.text()).toBe(on)
})


issue .

+5

Source: https://habr.com/ru/post/1688038/


All Articles