GithubHelp home page GithubHelp logo

Jasmine support about enzyme HOT 5 CLOSED

enzymejs avatar enzymejs commented on April 28, 2024
Jasmine support

from enzyme.

Comments (5)

lelandrichardson avatar lelandrichardson commented on April 28, 2024

@just-boris thanks for bringing this up. Can you post the code that is actually causing this to throw?

There are a couple of assumptions made in the library about mocha being present, however these are mostly undocumented features which are used internally at Airbnb but will likely be removed.

Running mount() on it's own should not be requiring a before function being present. The only thing I can find that would, actually, is the useSetStateHack() export?

I could be missing something though. A stack trace would be helpful.

from enzyme.

just-boris avatar just-boris commented on April 28, 2024

The error has been caused by describeWithDOM. This is my usage example:

describeWithDOM('<Component />', function() {
    it('should be rendered without errors', function() {
        const component = mount(<Component />)
    })
});

The describeWithDOM is necessary wrapper to use mount, as it follows from docs.

from enzyme.

lelandrichardson avatar lelandrichardson commented on April 28, 2024

@just-boris I see. I think we should make some documentation changes to more accurately reflect what is necessary. There is a good chance that describeWithDOM will be removed from the library in a later release, as it is definitely mocha specific.

In order to use mount, you need only to have DOM API's present in the global scope. If you would like to use jsdom, as long as you have the DOM loaded in the global scope when you make the call to mount(), everything should work.

the describeWithDOM function is used in conjunction with mocha for two reasons:

  1. It re-instantiates a new DOM before every test so that tests don't have any side effects on other tests
  2. It automatically skips the test if it is being run in an environment where jsdom cannot be loaded (ie, node < 4).

If you're running the tests in an environment with DOM API's, mount should "just work" without the use of describeWithDOM.

Let me know if that makes sense?

from enzyme.

just-boris avatar just-boris commented on April 28, 2024

Yes, I can set up jsdom by myself and it seems to be working.

But desctibeWithDOM is very nice, it doesn't require a lot of setup frictions, it just works. As far as I see, the issue is that describeWithDOM relied on mocha-jsdom. So, if I want to make it work with jasmine, I can make similar module jasmine-jsdom. By the way, the name is free and I am going to take it.

from enzyme.

lelandrichardson avatar lelandrichardson commented on April 28, 2024

@just-boris there is some discussion about creating additional test-runner-specific modules like mocha-reagent and karma-reagent, etc. that would have some of these conveniences built-in. describeWithDOM may get graduated to such a library, and retired here.

from 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.