Skip to content

Commit

Permalink
fix: guards content.mimeType.includes
Browse files Browse the repository at this point in the history
  • Loading branch information
moltar committed Apr 4, 2020
1 parent ebae152 commit ff86fcd
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/jest-polly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ Polly.on('create', polly => {
.on('beforePersist', (req, recording) => {
const { content } = recording.response

if (content.mimeType.includes('application/json')) {
if (
content &&
content.mimeType &&
content.mimeType.includes('application/json')
) {
try {
content.text = JSON.parse(content.text)
} catch (e) {
Expand All @@ -26,7 +30,11 @@ Polly.on('create', polly => {
.on('beforeReplay', (req, recording) => {
const { content } = recording.response

if (content.mimeType.includes('application/json')) {
if (
content &&
content.mimeType &&
content.mimeType.includes('application/json')
) {
try {
content.text = JSON.stringify(content.text)
} catch (e) {
Expand All @@ -49,6 +57,8 @@ export const jestPollyContext: JestPollyContext = setupPolly()

// and then before each test run, we'll update it with actual configuration, because
// some of the configuration, depends on being inside a test
beforeEach(() => jestPollyContext.polly.configure(jestPollyConfigService.config))
beforeEach(() =>
jestPollyContext.polly.configure(jestPollyConfigService.config),
)

afterEach(() => jestPollyContext.polly.flush())

0 comments on commit ff86fcd

Please sign in to comment.