Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jasmine support #55

Closed
just-boris opened this issue Dec 6, 2015 · 5 comments
Closed

Jasmine support #55

just-boris opened this issue Dec 6, 2015 · 5 comments

Comments

@just-boris
Copy link
Contributor

As it follows from the docs

Reagent is unopinionated regarding which test runner or assertion library you use, and should be compatible with all major test runners and assertion libraries out there.

I tried to use it with Jasmine and it worked fine until I tried to use mount. I got the error.

TypeError: before is not a function

before hook is the Mocha-specific thing, Jasmine has the similar thing named beforeAll.

Thanks for the awesome tool! It is really missing piece to my tests, but I can't use it due to lack of Jasmine support.

@lelandrichardson
Copy link
Collaborator

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

@just-boris
Copy link
Contributor Author

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.

@lelandrichardson
Copy link
Collaborator

@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?

@just-boris
Copy link
Contributor Author

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.

@lelandrichardson
Copy link
Collaborator

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

lelandrichardson added a commit that referenced this issue Dec 8, 2015
This refactor addresses several issues regarding enzyme working in a variety of environments, and
the library just generally not making any assumptions about the environment that tests will be
run in.

For the most part, this amounts to:

- remove direct dependency on jsdom
- remove direct dependency on sinon
- remove assumed dependency on mocha

Additionally, this change moves the code that was removed into separate modules that are
defined in the packages folder. In this case we have added two modules: "enzyme-mocha" and
"enzyme-sinon".

This design will allow us to have one repo where all issues, code, and documentation
regarding enzyme are centralized, but modules are still separated at the NPM level. This
will allow us to make atomic releases across the modules more easily, as well as keep
all of the discussion in one place.

Left to do before this is mergable:

 [ ] Add a "guides" section in the docs explaining how to use enzyme in different environments
 [ ] Build a proper npm script to run an npm publish in the proper order for each module
 [ ] Add more meaningful tests for packages

This PR addresses several issues that havee been brought up:

- Fixes #55
- Fixes #47
- Fixes #44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants