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 read property 'ids' of undefined, help needed #13

Closed
bboguszewski opened this issue Dec 30, 2019 · 5 comments
Closed

Comments

@bboguszewski
Copy link

While I'm trying to mock Request form express I have following error message:

Test suite failed to run

    TypeError: Cannot read property 'ids' of undefined

      at node_modules/ts-auto-mock/transformer/index.js:1:31921
      at node_modules/ts-auto-mock/transformer/index.js:1:31934
          at Array.forEach (<anonymous>)
      at Object.addFromDeclarationExtension (node_modules/ts-auto-mock/transformer/index.js:1:31656)
      at node_modules/ts-auto-mock/transformer/index.js:1:15906
          at Array.forEach (<anonymous>)
      at node_modules/ts-auto-mock/transformer/index.js:1:15752
          at Array.forEach (<anonymous>)
      at u (node_modules/ts-auto-mock/transformer/index.js:1:15723)
      at Object.t.GetMockFactoryCall (node_modules/ts-auto-mock/transformer/index.js:1:16178)

Test which results in this error is below

import {Request} from 'express'
import each from 'jest-each'
import {createMock} from 'ts-auto-mock'

const notFoundError = (req: Request) => {
    throw new Error(req.method + ' ' + req.url + ' not found...')
}

describe('notFoundError', () => {
    each([
        ['GET', '/test/get/path', 'GET /test/get/path not found...'],
        ['POST', '/test/post/path', 'POST /test/post/path not found...'],
    ]).test('%s,%s', async (method, url, message) => {
        const mockRequest = createMock<Request>();
        mockRequest.method = method
        mockRequest.url = url
        try {
            notFoundError(mockRequest)
        } catch (e) {
            expect(e.toString()).toMatch(message)
        }
    })
})

I'm using "express": "^4.17.1",, "jest-ts-auto-mock": "^1.0.8", and "ts-auto-mock": "^1.4.3",. Any idea how to resolve it?

@uittorio
Copy link
Member

Hi, I'm sorry you are finding more issues. That ids error indicates that something got wrong when generating generics. I'll keep you updated :)

@bboguszewski
Copy link
Author

No worries. It's the only way I can contribute ;)

@uittorio
Copy link
Member

Hi again, I had a quick look. Something is wrong with defaults generics. I've tried to default the generic doing this but there is another issue related to that generic.

createMock<Request<{ [key: string]: string; }>>();

You may have to wait few more days to use that interface

@uittorio
Copy link
Member

uittorio commented Jan 1, 2020

@barthpl morning and happy new year :) A new version has been released. 1.0.10 :) I've tested it with the entire express module. It should work, let me know if you have any issue. You may have to install the latest of ts-auto-mock if you've installed separately.

@bboguszewski
Copy link
Author

@uittorio happy new year to you too. Fix works perfect. Thank you.
If you decide to come to Wroclaw (Poland) let me know - I own you a bear.

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