Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing best practice #616

Closed
Edweis opened this issue Jan 28, 2020 · 4 comments
Closed

Testing best practice #616

Edweis opened this issue Jan 28, 2020 · 4 comments

Comments

@Edweis
Copy link

Edweis commented Jan 28, 2020

What is the best practice to test graphql-yoga server ? I'd like to use chai testing like in express for instance. Is it possible ?

@Edweis
Copy link
Author

Edweis commented Jan 29, 2020

Found it.
You can export the app const app = server.start(...) and in the test wait for it to be finished :

const chai = require('chai');
const chaiHttp = require('chai-http');
const appPromise = require('../server');
let app = null;

const { expect } = chai;
chai.use(chaiHttp);

beforeAll(async () => {
  app = await appPromise;
});

describe('Health', () => {
  it.skip('should validate health check', async () => {
    expect(1).to.equals(1);
    // await checkHealth(false);
  });

  it('should get bricks', async () => {
    const res = await chai
      .request(app)
      .post('/')
      .send({ query: '{ feed { id }}' });
    expect(res).to.have.status(200);
    expect(res.body.data.feed).to.exist;
  });
});

@dunatron
Copy link

dunatron commented Sep 7, 2020

@Edweis Do you by any chance have an example of how to do a mutation with data?

@Knautiluz
Copy link

@Edweis Do you by any chance have an example of how to do a mutation with data?
Instead of: .send({ query: '{ feed { id }}' }); use: .send({ query: `mutation { ${mutation} }` })

@saihaj saihaj mentioned this issue Dec 5, 2021
32 tasks
@saihaj
Copy link
Collaborator

saihaj commented Feb 19, 2022

Hey @Edweis @dunatron @Knautiluz we @the-guild-org are the new maintainers for this project. We are working actively on v2 to address all the issues. Testing is a critical part of software development and the new Yoga Server comes with built in way to test https://www.graphql-yoga.com/docs/testing. You can try out the beta release @graphql-yoga/node@beta and give us feedback. Thanks!

@saihaj saihaj closed this as completed Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants