Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Is possible to use these scripts with mocha-chai-enzyme instead of jest? #86

Closed
CzBuCHi opened this issue Jun 16, 2017 · 3 comments
Closed
Labels

Comments

@CzBuCHi
Copy link

CzBuCHi commented Jun 16, 2017

Question is in title, here is my reason why:


in mocha-chai-enzyme combo i can write test like this:

function TestComponent({ value, doClick }){ // react stateless component
  return (
    <div className="test-component" onClick={ e => doClick(value) }>
      { value && <TestComponent Value={ value - 1 } doClick={ doClick } /> }
    </div>
  );
}

describe('Test', function () {
  it('Success', function () {
    const props = { 
      value: 42, 
      doClick: () => { } // functions are checked only for existence, not content
    };    
    const actual = shallow(<TestComponent {...props} />);    
    const expected = // basically copy-pastle of TestComponent return value...
      <div className="test-component" onClick={ () => { } }>
        <TestComponent Value={ 41 } doClick={ () => { } } />
      </div>;    
    expect(actual).toEqualJSX(expected); // toEqualJSX from './jsxEqual'
  });
});

instead of something like:

expect(actual.find('.test-component')).to.have.length(1);
expect(actual.find(TestComponent)).to.have.length(1);
expect(actual.find(TestComponent).props.value).to.be.equal(41);
expect(actual.find(TestComponent).props.doClick).to.be.not.null;
...

i dont wanna loose that but also like no-config configuration of cra-ts ....

@wmonk
Copy link
Owner

wmonk commented Jun 16, 2017

It isn't possible to use mocha but I think it's possible to use chai-enzyme. Airbnb actually released a blog post today in which they describe using chai with jest. So you can just require in { expect } from chai.

@wmonk
Copy link
Owner

wmonk commented Jun 16, 2017

On a side note, personally I don't think it's valuable to test components in the way you describe above. While I don't use this testing strategy, Snapshot testing sounds very similar to what you you're doing in your example.

@wmonk wmonk added the question label Jun 16, 2017
@CzBuCHi
Copy link
Author

CzBuCHi commented Jun 16, 2017

i have zero experience with jest - but snaphots looks really pretty to me :) ... so im guessing i will switch to jest after all :)

@CzBuCHi CzBuCHi closed this as completed Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants