Giter VIP home page Giter VIP logo

Comments (8)

SSmale avatar SSmale commented on July 3, 2024 1

sorry to jump on this question but I am having an issue testing a service that uses the HTTPService so wondered if there was an example of the spec file?

https://discord.com/channels/520622812742811698/520649487924985885/765515369116073984 some code examples of my issue and any discussion that comes after

from testing-nestjs.

jeoy avatar jeoy commented on July 3, 2024

Or can you give some advice do we need mock axios request for e2e test?

from testing-nestjs.

jmcdo29 avatar jmcdo29 commented on July 3, 2024

By "Axios" are you meaning the npm package, or the built in HttpService that is a wrapper around axios?

from testing-nestjs.

jeoy avatar jeoy commented on July 3, 2024

By "Axios" are you meaning the npm package, or the built in HttpService that is a wrapper around axios?

What's the difference between these two ?
Consider that our service depend on other http service where we use axios (or fetch) to get data from

from testing-nestjs.

jmcdo29 avatar jmcdo29 commented on July 3, 2024

What's the difference between these two?

The built in HttpService is a wrapper around axios and uses Observables, whereas axios the npm package is a direct http client that uses promises or callbacks, so the testing of the two is different.

How do your see this test going, are you using a package directly or a service as a wrapper? In my opinion one is easier to work with than the other when it comes to writing tests.

from testing-nestjs.

jeoy avatar jeoy commented on July 3, 2024

Well, i am using a npm package directly.

import axios  from 'axios';

axios.get(url).then(res => {... })

BTW:
🀣what a coincidence i just saw your answer in this stackflow question

from testing-nestjs.

jmcdo29 avatar jmcdo29 commented on July 3, 2024

If this isn't about mocking a provider in Nest, I would say that it falls out of the scope of what this repository is for. There are several tutorials and articles out there showing how you can use jest.mock() and jest.spyOn() along with other methods to mock npm packages in unit or e2e scopes, as Jest doesn't consider them different at all.

from testing-nestjs.

jeoy avatar jeoy commented on July 3, 2024

ok cool

from testing-nestjs.

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.