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

TypeError: Cannot set property 'handlers' of undefined #344

Open
eau-de-la-seine opened this issue Jul 11, 2022 · 1 comment
Open

TypeError: Cannot set property 'handlers' of undefined #344

eau-de-la-seine opened this issue Jul 11, 2022 · 1 comment

Comments

@eau-de-la-seine
Copy link

Hello Colin,

Encountered error: TypeError: Cannot set property 'handlers' of undefined

Project type: Back-end NodeJS with ES6 modules

Dependencies:

  • axios version ^0.27.2
  • axios-mock-adapter version ^1.21.1
  • jasmine version ^4.2.1 (the only JS test framework that works properly with ES6 modules and without transpilers)

Code:

'use strict'

import axios from 'axios'
import MockAdapter from 'axios-mock-adapter'

let mockServer = MockAdapter(axios)

Stacktrace:

npm test

> lambda_sync_order@0.0.0 test
> jasmine

TypeError: Cannot set property 'handlers' of undefined
    at resetHandlers (/home/gekinci/my-projects/infra/wco_services/lambdas/sync-order/node_modules/axios-mock-adapter/src/index.js:41:17)
    at reset (/home/gekinci/my-projects/infra/wco_services/lambdas/sync-order/node_modules/axios-mock-adapter/src/index.js:36:17)
    at MockAdapter (/home/gekinci/my-projects/infra/wco_services/lambdas/sync-order/node_modules/axios-mock-adapter/src/index.js:49:9)
    at file:///home/gekinci/my-projects/infra/wco_services/lambdas/sync-order/utils/audit/audit-axios-client.test.js:6:18
    at ModuleJob.run (internal/modules/esm/module_job.js:152:23)
    at async Loader.import (internal/modules/esm/loader.js:177:24)
    at async Jasmine._loadFiles (/home/gekinci/my-projects/infra/wco_services/lambdas/sync-order/node_modules/jasmine/lib/jasmine.js:215:5)
    at async Jasmine.loadSpecs (/home/gekinci/my-projects/infra/wco_services/lambdas/sync-order/node_modules/jasmine/lib/jasmine.js:206:3)
    at async Jasmine.execute (/home/gekinci/my-projects/infra/wco_services/lambdas/sync-order/node_modules/jasmine/lib/jasmine.js:502:3)
    at async runJasmine (/home/gekinci/my-projects/infra/wco_services/lambdas/sync-order/node_modules/jasmine/lib/command.js:157:5)
@jndietz
Copy link

jndietz commented Oct 1, 2022

I just ran into this myself. Try instantiating the MockAdapter with the new keyword:

let mockServer = new MockAdapter(axios)
                  👆

Tangentially, I had to use the result of axios.create(), which returns an AxiosInstance, instead of plain axios which is typed as AxiosStatic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants