Code Monkey home page Code Monkey logo

fake-fetch's People

Contributors

msn0 avatar omrilotan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

stringerbell eml

fake-fetch's Issues

Feature request: public method to access returning Promise

Hello there!
I think it would very useful to be able to access the Promise returning from fetch.
For instance, if my code is something like this:

export function functionToBeTested()  {
  fetch('url', options).then((res) => {
    someLogicIWantToTest(res);
  } )

With the actual API I'm not able to test that someLogicIWantToTest has been called with the correct args.

My proposed solution is to return the Promise from respondWith

module.exports.respondWith = function (data, options) {
    var response = Promise.resolve(new Response(data, options));
    window.fetch.returns(response);
    return response;
};

so I would be able to write a test like:

it('tests some logic', function (done) {
    var mockedResponse = fakeFetch.respondWith({ok: true});
    functionToBeTested();
    mockedResponse.then(() => {
         expect(someLogicIWantToTest).toHaveBeenCalledWith(res);
         done();
    })
})

Let me know if something is not clear!

es module output

The code published to NPM is commonjs, which can't be run in the browser without transformations.

It would be great if you could provide an output using standard es modules, so that this library can run in the browser directly. As an example, sinon uses rollup to generate an esm bundle (https://github.com/sinonjs/sinon).

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.