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

Synchronous testing functions #292

Open
jasonkuhrt opened this issue Jan 16, 2020 · 0 comments
Open

Synchronous testing functions #292

jasonkuhrt opened this issue Jan 16, 2020 · 0 comments
Labels
scope/testing type/feat Add a new capability or enhance an existing one

Comments

@jasonkuhrt
Copy link
Member

What

  • Testing module is currently async, for example:

    // tests/user.test.ts
    
    import { createTestContext } from './__helpers'
    
    const ctx = createTestContext()
    
    it('makes sure a user was registered', async () => {
      const result = await ctx.app.query(`
        mutation {
          signupUser(data: { email: "person@email.com", password: "123456" })
        } {
          id
          email
          password
        }
      `)
    
      const createdUsers = await ctx.app.query(`{ users { id } }`)
      expect(createdUsers).toMatchSnapshot()
    })
  • But in a testing context synchronous is usually easier to work with:

    // tests/user.test.ts
    
    import { createTestContext } from './__helpers'
    
    const ctx = createTestContext()
    
    it('makes sure a user was registered', () => {
      const result = ctx.app.query(`
        mutation {
          signupUser(data: { email: "person@email.com", password: "123456" })
        } {
          id
          email
          password
        }
      `)
    
      expect(ctx.app.query(`{ users { id } }`)).toMatchSnapshot()
    })
  • We could drop async API or make it opt-in, e.g.:

     createTestContext({ async: true }) // makes functions on ctx be async

    or async function prop on sync functions:

     ctx.app.query() // Result
     ctx.app.query.async() // Promise<Result>
@jasonkuhrt jasonkuhrt added type/feat Add a new capability or enhance an existing one scope/testing labels Jan 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope/testing type/feat Add a new capability or enhance an existing one
Projects
None yet
Development

No branches or pull requests

1 participant