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

feat: mock as object syntax #411

Open
AndersDJohnson opened this issue Aug 10, 2019 · 0 comments
Open

feat: mock as object syntax #411

AndersDJohnson opened this issue Aug 10, 2019 · 0 comments
Assignees

Comments

@AndersDJohnson
Copy link
Member

AndersDJohnson commented Aug 10, 2019

Allow mocks to export an object syntax instead of nested arrays (and let mockyeah.get(), etc. accept these as a single argument), e.g.:

{
  match: 'http://example.com',
  options: {
    text: 'ok'
  }
}

or perhaps (maybe also):

{
  request: 'http://example.com',
  response: {
    text: 'ok'
  }
}

or:

{
  req: 'http://example.com',
  res: {
    text: 'ok'
  }
}

Use programmatically:

mockyeah.get({
  match: 'http://example.com',
  options: {
    text: 'ok'
  }
});

Use in mock suite:

module.exports = {
  mocks: [
    {
      match: 'http://example.com',
      options: {
        text: 'ok'
      }
    }
  ]
}

This wrapping object would allow us to add metadata to the suites or make it extensible for other options in the future, such as a description, a default latency or other settings per-suite, e.g.:

module.exports = {
  description: "This suite does things.",
  latency: 1000,
  mocks: [
    {
      description: "This mock does things",
      match: 'http://example.com',
      options: {
        text: 'ok'
      }
    }
  ]
}

Or perhaps (optionally) more simply, just an array of objects:

module.exports = [
  {
    match: 'http://example.com',
    options: {
      text: 'ok'
    }
  }
]

See also single suite option #410, and suite files as JSON #414.

@AndersDJohnson AndersDJohnson self-assigned this Aug 10, 2019
@AndersDJohnson AndersDJohnson changed the title feat: optional object syntax for suite export feat: optional mock object syntax Nov 19, 2019
@AndersDJohnson AndersDJohnson changed the title feat: optional mock object syntax feat: mock as object syntax Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant