@revoloo/cypress6
Version:
Cypress.io end to end testing tool
21 lines (16 loc) • 536 B
text/typescript
import { find } from 'lodash'
import { CyHttpMessages } from '@packages/net-stubbing/lib/types'
export function hasJsonContentType (headers: { [k: string]: string }) {
const contentType = find(headers, (v, k) => /^content-type$/i.test(k))
return contentType && /^application\/json/i.test(contentType)
}
export function parseJsonBody (message: CyHttpMessages.BaseMessage) {
if (!hasJsonContentType(message.headers)) {
return
}
try {
message.body = JSON.parse(message.body)
} catch (e) {
// invalid JSON
}
}