Comments (2)
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.
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)
- [1.0.0-beta.0] Cannot assert descendant not present HOT 2
- Use of reserved word 'let' in strict mode HOT 3
- [1.0.0-beta.0] className assertion failing when element has multiple classNames HOT 10
- CLOSED: Dependency issues with new version of enzyme HOT 4
- React 15.0.0 and Enzyme 3.2.0 issue HOT 3
- Cannot find module 'enzyme/build/react-compat' HOT 4
- Cannot convert a Symbol value to a string
- to.have.text(undefined) does not break the tests
- Error message for shallow render contains HOT 4
- Patch version bump for fix merged in from PR#215? HOT 2
- Is this library still maintained? `[import Adapter from 'enzyme-adapter-react-15';]` HOT 5
- .should.have.html(...) broken in 1.0.0-beta.1
- .to.have.style() requires kebab-cased keys
- TypeError: to.have.style is not a function HOT 1
- setup is vague
- Flow types HOT 1
- Preact support? HOT 3
- Chai's `assert.` style supported ? HOT 2
- Cannot read property 'have' of undefined
- Support for React 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chai-enzyme.