Coder Social home page Coder Social logo

Testing API requests with Japa. about core HOT 2 CLOSED

japa avatar japa commented on July 23, 2024
Testing API requests with Japa.

from core.

Comments (2)

thetutlage avatar thetutlage commented on July 23, 2024 1

Hello 👋

Japa is just a test runner. It means, it can only run tests and assertions for you. For extra features, you will have to install other packages.

For example, you can use https://www.npmjs.com/package/supertest for testing API calls.

from core.

jlenon7 avatar jlenon7 commented on July 23, 2024

Thank you so much Virk, It's working !!

// Database stuffs
import createConnection from '../../database'
import { Connection, getRepository, getConnection } from 'typeorm'

// Japa for testing supertest to make requests
import test from 'japa'
import request from 'supertest'

// Models
import Summoner from '../../Models/Summoner'

// Import app to run and make requests
import app from '../../app'

let connection: Connection

 // Run this test with the command:
 //  ts-node src/__tests__/functional/Summoner.spec.ts
 // Or run all tests with node japaFile.js

test.group('Summoner Tests', (group) => {
  group.before(async () => {
    connection = await createConnection('test-connection');
    await connection.runMigrations();
  });

  group.beforeEach(async () => {
    await connection.query('DELETE FROM summoners');
  });

  group.after(async () => {
    const mainConnection = getConnection();

    await connection.close();
    await mainConnection.close();
  });

  const region = 'br1'
  const summoner = 'iLenon7'

  test('create ilenon7', async (assert) => {
    const response = await request(app).post(`/gg/v1/summoners?region=${region}&summonerName=${summoner}`)

    assert.exists(response.body.summoner)
  })
})

from core.

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.