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

Implement toBeRequestedWith matcher #184

Closed
mgrybyk opened this issue Sep 4, 2020 · 0 comments
Closed

Implement toBeRequestedWith matcher #184

mgrybyk opened this issue Sep 4, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request network mock

Comments

@mgrybyk
Copy link
Member

mgrybyk commented Sep 4, 2020

Let's implement a new matcher that works this:

const searchMock = browser.mock('**/search?*', { method: 'POST' })
$('search').click()
// POST http://localhost:8080/tst/invoices/search?size=20&page=0&sort=createdDateTime,desc'
// body { foo: 'bar', released: true }
expect(searchMock).toBeRequestedWith({
  method: 'POST',
  url: (url) => url.includes('invoices') && url.includes('localhost'),
  request: { released: true },
  query: { size: 20 },
  headers: (headers) => headers.Authorization.startsWith('Bearer '),
}, { containing: true })
// types.d.ts
toBeRequestedWith({
  method: string
  url: string | (url: string) => boolean
  request: string | Record<string: unknown> | Array<Record<string: unknown>> | (payload: unknown) => boolean
  query: string | Record<string: string>| (query: Record<string: string>) => boolean
  headers: Record<string: string> | (headers: Record<string: string>) => boolean
}): R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request network mock
Projects
None yet
Development

No branches or pull requests

1 participant