Giter Site home page Giter Site logo

Comments (13)

arizzitano avatar arizzitano commented on May 22, 2024

I just noticed this too. Tests pass even if I pass junk into the mockStore() init call, e.g. mockStore('asdf', done). Using redux-mock-store 0.0.6 with jasmine/karma and mocking XHRs with karma-jasmine-ajax.

from redux-mock-store.

jwbennet avatar jwbennet commented on May 22, 2024

I believe that this library supports Mocha instead of Jasmine and the two libraries differ on how they use the done function. With Mocha, calling the done function with an error will fail the spec, but in Jasmine there is a special done.fail function which needs to be called to fail the spec (see the docs for async support). For now I'm working around it by passing in the done function like this:

const store = mockStore({ }, expectedActions, (e) => {
      if(e instanceof Error) {
        done.fail(e);
      } else {
        done(e);
      }
    });

from redux-mock-store.

jdmunro avatar jdmunro commented on May 22, 2024

Thanks @jwbennet your explanation makes complete sense, I'll use your workaround. I don't know if @arnaudbenard is interested in also supporting Jasmine. I can maybe put together a PR, if not feel free to close this issue.

from redux-mock-store.

arizzitano avatar arizzitano commented on May 22, 2024

@jwbennet thanks for the workaround!

@jdmunro @arnaudbenard +1 for Jasmine support (or a framework-agnostic fork).

from redux-mock-store.

arnaudbenard avatar arnaudbenard commented on May 22, 2024

Is there an easy method to detect if we are using Jasmine or mocha?

If that's the case, I'm happy to support Jasmine

from redux-mock-store.

jdmunro avatar jdmunro commented on May 22, 2024

I had a pragmatic solution in mind:

if (done.fail) {
    done.fail(e);
} else {
    // ... current exception handling.
}

It isn't the most robust solution but it should do the trick for now. Alternatively we can just look for the presence of the jasmine variable.

from redux-mock-store.

erquhart avatar erquhart commented on May 22, 2024

I think the greater issue here is how redux-mock-store bypasses my assertion library. I've put a fair amount of time into integrating redux-mock-store into my tests, and I now feel strongly that this is an anti-pattern that will probably bite a lot of folks.

A mocking lib should not handle setting expectations. It should simply provide an interface that helps devs run isolated test scenarios. A mocking lib shouldn't need to support any test framework - it's probably fair to say the issue of supporting mocha vs jasmine is an xy problem.

For now I'll be using spies when I need to mock around stores, but I do love the idea of using a lib like this - it just needs less responsibility. I guess we'll see if the guy who's actually doing something about this for the community agrees :)

At any rate, thanks for your work, mate.

from redux-mock-store.

arnaudbenard avatar arnaudbenard commented on May 22, 2024

I agree with @erquhart. The library should be framework agnostic. I have noticed that other people had problems with Jasmine and tape as well. I am not sure how to handle that yet. Do you have examples of libraries that have the same type of API?

from redux-mock-store.

erquhart avatar erquhart commented on May 22, 2024

I've commented on #22.

from redux-mock-store.

 avatar commented on May 22, 2024

Thanks for the workaround @jwbennet

from redux-mock-store.

nikolasleblanc avatar nikolasleblanc commented on May 22, 2024

In the meantime, here's a temporary module for Jasmine (and Mocha): https://www.npmjs.com/package/redux-mock-store-jasmine

from redux-mock-store.

arnaudbenard avatar arnaudbenard commented on May 22, 2024

There's a new version out, please give it a try 👊

from redux-mock-store.

nikolasleblanc avatar nikolasleblanc commented on May 22, 2024

Excellent, thanks @arnaudbenard

from redux-mock-store.

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.