GithubHelp home page GithubHelp logo

Comments (2)

ayrton avatar ayrton commented on June 17, 2024

Confirmed this is indeed a bug when the component is mounted (not when using shallow or render):

class NullFixture extends React.Component {
  render () {
    return (<p>hi</p>)
  }
}

const it = createTest(<NullFixture />)

describe('#blank', () => {
  describe('()', () => {
    it('passes negated when the actual does not match the expected', (wrapper) => {
      expect(wrapper).to.not.be.blank()
    })
  })
})

Results:

$ NODE_ENV=test npme mocha test/blank.test.js


  #blank
    ()
      ✓ (shallow): passes negated when the actual does not match the expected
      1) (mount): passes negated when the actual does not match the expected
      ✓ (render): passes negated when the actual does not match the expected


  2 passing (161ms)
  1 failing

  1) #blank () (mount): passes negated when the actual does not match the expected:
     AssertionError: expected <NullFixture /> not to be empty

     HTML:

     <p data-reactroot="">hi</p>
      at blank.test.js:12:33
      at Context.<anonymous> (createTest.js:20:7)
      at callFn (/Users/adc/Developer/producthunt/chai-enzyme/node_modules/mocha/lib/runnable.js:334:21)
      at Test.Runnable.run (/Users/adc/Developer/producthunt/chai-enzyme/node_modules/mocha/lib/runnable.js:327:7)
      at Runner.runTest (/Users/adc/Developer/producthunt/chai-enzyme/node_modules/mocha/lib/runner.js:428:10)
      at /Users/adc/Developer/producthunt/chai-enzyme/node_modules/mocha/lib/runner.js:534:12
      at next (/Users/adc/Developer/producthunt/chai-enzyme/node_modules/mocha/lib/runner.js:348:14)
      at /Users/adc/Developer/producthunt/chai-enzyme/node_modules/mocha/lib/runner.js:358:7
      at next (/Users/adc/Developer/producthunt/chai-enzyme/node_modules/mocha/lib/runner.js:284:14)
      at Immediate.<anonymous> (/Users/adc/Developer/producthunt/chai-enzyme/node_modules/mocha/lib/runner.js:326:5)
      at runCallback (timers.js:574:20)
      at tryOnImmediate (timers.js:554:5)
      at processImmediate [as _immediateCallback] (timers.js:533:5)

from chai-enzyme.

cy6erskunk avatar cy6erskunk commented on June 17, 2024

The problem still exists, now in shallow and render, in case of non-empty component:

class NullFixture extends React.Component {
  render () {
    return (<AnotherNullFixture/>)
  }
}

class AnotherNullFixture extends React.Component {
  render () {
    return (<p>text</p>)
  }
}

it = createTest(<NullFixture />)

describe.only('#blank', () => {
  describe('(non-empty component)', () => {
    it('passes when the actual matches the expected', (wrapper) => {
      expect(wrapper).to.not.be.blank()
    })

    // it('fails when the actual does not match the expected', (wrapper) => {
    //   expect(() => {
    //     expect(wrapper).to.be.blank()
    //   }).to.throw()
    // })
  })
})

Results:

NODE_ENV=test npx mocha test/blank.test.js


  #blank
    (non-empty component)
      1) (shallow): passes when the actual matches the expected
      ✓ (mount): passes when the actual matches the expected
      2) (render): passes when the actual matches the expected


  1 passing (365ms)
  2 failing

  1) #blank (non-empty component) (shallow): passes when the actual matches the expected:
     AssertionError: expected <NullFixture /> not to be empty

     HTML:

     <p>text</p>
      at /Users/user/Documents/_prj/chai-enzyme/test/blank.test.js:60:33
      at Context.<anonymous> (/Users/user/Documents/_prj/chai-enzyme/test/support/createTest.js:14:7)
      at callFn (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runnable.js:348:21)
      at Test.Runnable.run (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runnable.js:340:7)
      at Runner.runTest (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:443:10)
      at /Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:549:12
      at next (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:361:14)
      at /Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:371:7
      at next (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:295:14)
      at Immediate.<anonymous> (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:339:5)
      at runCallback (timers.js:789:20)
      at tryOnImmediate (timers.js:751:5)
      at processImmediate [as _immediateCallback] (timers.js:722:5)

  2) #blank (non-empty component) (render): passes when the actual matches the expected:
     AssertionError: expected the node in <??? /> not to be empty

     HTML:

     <p>text</p>
      at /Users/user/Documents/_prj/chai-enzyme/test/blank.test.js:60:33
      at Context.<anonymous> (/Users/user/Documents/_prj/chai-enzyme/test/support/createTest.js:26:7)
      at callFn (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runnable.js:348:21)
      at Test.Runnable.run (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runnable.js:340:7)
      at Runner.runTest (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:443:10)
      at /Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:549:12
      at next (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:361:14)
      at /Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:371:7
      at next (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:295:14)
      at Immediate.<anonymous> (/Users/user/Documents/_prj/chai-enzyme/node_modules/mocha/lib/runner.js:339:5)
      at runCallback (timers.js:789:20)
      at tryOnImmediate (timers.js:751:5)
      at processImmediate [as _immediateCallback] (timers.js:722:5)

It seems not correct to check children in these cases in isEmpty, why not use exists from enzyme, which is the replacement for the deprecated method isEmpty?

from chai-enzyme.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.