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

Document that the jest code mods won't cover all cases? #230

Open
jharris4 opened this issue Sep 9, 2017 · 4 comments
Open

Document that the jest code mods won't cover all cases? #230

jharris4 opened this issue Sep 9, 2017 · 4 comments

Comments

@jharris4
Copy link

jharris4 commented Sep 9, 2017

I'm trying out migrating from mocha & expect to just jest.

The code mods handled most of the cases, but there are some MAJOR differences in how Jest's isEqual matcher works, mostly because it does not use the is-equal package anymore.

This means things like this worked with expect but DO NOT work with jest:

expect(["abc"]).toEqual("abc");
function createEnhancedFunction() {
  var myFunction = function() { return "a value"; };
  myFunction.a = "123";
  return myFunction;
}

expect({ a: createEnhancedFunction() }).toEqual({ a: createEnhancedFunction() });

The first difference is easy to work around, but the second one (inability to compare functions and treat them as equal) has me a little stumped.

I'd think it would be good to emphasize that is-equal is no longer used for equality checks, and maybe suggest some workarounds in the docs?

@ljharb
Copy link
Collaborator

ljharb commented Sep 9, 2017

Issues with expect v21+ need to be filed in the jest repo: https://github.com/facebook/jest

@ljharb ljharb closed this as completed Sep 9, 2017
@jharris4
Copy link
Author

jharris4 commented Sep 9, 2017

@ljharb This issue was specific to helping people migrate to the new package FROM the old expect package.

As such, I was pointing out that people coming here looking to move there could use some extra pointers than what is currently in the README.

At the very least, it would be good to make it clear in the README that the codemods won't give you full feature compatibility with expect v21+

@ljharb
Copy link
Collaborator

ljharb commented Sep 9, 2017

Fair point; I'll reopen this - but I'd still file an issue in the jest repo about it.

@ljharb ljharb reopened this Sep 9, 2017
@jharris4
Copy link
Author

jharris4 commented Sep 9, 2017

Thanks, when I have a little more time, I hope to file a PR here to update the README.

I'm currently using the following workaround to make my old tests pass with jest, and yeah, I may well file an issue/PR with jest related to it once I've clarified my thinking a bit.

import isEqual from "is-equal";

var customMatchers = {
  toIsEqual: function() {
    return {
      compare: function(actual, expected) {
        return {
          pass: isEqual(actual, expected)
        };
      }
    };
  }
};

beforeEach(function() {
  jasmine.addMatchers(customMatchers);
});

Basically, it lets you replace the old expect().toEqual with expect().toIsEqual which is a bit hacky but did the trick for me.

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