Coder Social home page Coder Social logo

Examples with Testing about docs HOT 7 CLOSED

theodesp avatar theodesp commented on June 3, 2024 1
Examples with Testing

from docs.

Comments (7)

viglioni avatar viglioni commented on June 3, 2024 1

Thanks a lot!

Also congratulations for the lib :)

from docs.

JozefFlakus avatar JozefFlakus commented on June 3, 2024

Yup, that's right. I will try to update the docs with a new topic inside Advanced group. It will reflect the integration tests topic. 💪

from docs.

JozefFlakus avatar JozefFlakus commented on June 3, 2024

Solved with introduction of @marblejs/testing
https://docs.marblejs.com/testing/http-testing

from docs.

viglioni avatar viglioni commented on June 3, 2024

Sorry to comment on a closed issue or if I am in the wrong place, but I'm having a lot of trouble trying to test both ways

I'm using "@marblejs/core": "^3.5.0" also "@marblejs/testing": "^3.5.0"

I tried to upgrade to 4, but I had a lot of problems with rxjs 7, then I decided to go back to 3.5.0

I'm trying to do a very simple test:

The endpoint:

import { r } from '@marblejs/core'
import { mapTo } from 'rxjs/operators'

export const helloThere = r.pipe(
  r.matchPath('/'),
  r.matchType('GET'),
  r.useEffect(req => req.pipe(mapTo({ body: 'Hello there!' }))),
)

The test using jest:

const listener = httpListener({ effects: [helloThere] })

const httpTestBed = createHttpTestBed({
  listener,
})

 it('should return OK', async () => {
        const { request, finish } = await httpTestBed()

        const response = await pipe(
          request('GET'),
          request.withPath('/'),
          request.send,
        )
        
	expect(response.statusCode).toEqual(200)
				
        await finish()
      })

But I've got the error:

TypeError: Cannot read property 'path' of undefined

      at node_modules/@marblejs/core/dist/http/router/http.router.factory.js:13:59
          at Array.forEach (<anonymous>)
      at Object.<anonymous>.exports.factorizeRouting (node_modules/@marblejs/core/dist/http/router/http.router.factory.js:12:12)
      at Object.<anonymous>.exports.factorizeRoutingWithDefaults (node_modules/@marblejs/core/dist/http/router/http.router.factory.js:46:78)
      at node_modules/@marblejs/core/dist/http/server/http.server.listener.js:15:43
      at node_modules/fp-ts/lib/Reader.js:85:78
      at node_modules/@marblejs/core/dist/http/server/http.server.js:46:26
      at fulfilled (node_modules/@marblejs/core/dist/http/server/http.server.js:5:58)

Am I doing anything wrong?


The example with supertest doesn't work either.

node:internal/process/promises:246
         triggerUncaughtException(err, true /* fromPromise */);
         ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "TypeError: Cannot read property 'path' of undefined".] {
 code: 'ERR_UNHANDLED_REJECTION'
}

Thanks for your attention.

from docs.

JozefFlakus avatar JozefFlakus commented on June 3, 2024

Hi @viglioni,

Do you have a small reproducible repository that shows this problem?
I'm not sure if it will help you but the main repository shows an example usage of @marblejs/testing package.

Thanks!

from docs.

viglioni avatar viglioni commented on June 3, 2024

That example helped a lot! Thanks!!

I had seen only this example that I was not able to reproduce, probably because it was v2

This usually means that there are asynchronous operations that weren't stopped in your tests.

But I'm getting a strange promise error on Jest. Do you have any idea the reason?

https://github.com/Viglioni/marblejs-test-example

from docs.

JozefFlakus avatar JozefFlakus commented on June 3, 2024

@viglioni probably because you import the listener from main.ts which when evaluated (imported) starts listening to the server (it produces side effect):
https://github.com/Viglioni/marblejs-test-example/blob/main/src/main.ts#L23

I highly recommend to separate server and listener definitions and bootstrap them in a separate file.

from docs.

Related Issues (6)

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.