typescript-tdd / jest-ts-auto-mock Goto Github PK
View Code? Open in Web Editor NEWJest test utility with automatic mock creation for interfaces and classes
Jest test utility with automatic mock creation for interfaces and classes
git clone https://github.com/Typescript-TDD/jest-ts-auto-mock
cd jest-ts-auto-mock
npm i
npm run build
cd examples\ts-jest-ttypescript
npm i
npm t
FAIL reuse/2.test.ts
● Test suite failed to run
TypeError: Cannot read property 'map' of undefined
at transformBundle (node_modules/typescript/lib/typescript.js:77498:53)
FAIL reuse/1.test.ts
● Test suite failed to run
TypeError: Cannot read property 'map' of undefined
at transformBundle (node_modules/typescript/lib/typescript.js:77498:53)
FAIL ./basic.test.ts
● Test suite failed to run
TypeError: Cannot read property 'map' of undefined
at transformBundle (node_modules/typescript/lib/typescript.js:77498:53)
It looks like jest-ts-auto-mock
is stuck on a fairly old version of ts-auto-mock
(^1.5.0
). Is this package currently maintained? Or is there a technical reason it's hard to make newer features work with Jest? I'm grateful for your work, I just don't want to start relying on it for the first time if it's not getting any attention right now. :)
Requirements list typescript@^3.2.2 as dependency. Is there any plans on supporting typescript@^4?
Hey,
are there any plans to support jest 28?
Also, is there any roadmap/plans for newer versions of the lib?
I've tried to install jest-ts-auto-mock and add the file to setupFiles. Unfortunately it doesn't work. Using ts-auto-mock directly works perfectly
I have followed the guide on how to set this up, but that caused JSX/TSX files to not be transformed correctly. I read in the Jest configuration guide that currently only one transformer per file is supported and it seems like it is going to stay that way.
Could you add support or a guide on how to set this up without losing the other transformers?
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?
Hello guys.
first, thanks for this wonderful tool.
are you planning to add support for @swc/jest?
Hi
Is there an ongoing work to support Jest 27 ?
Thanks
I'm working with RabbitMQ library amqplib
and I have problem with mocking some object (amqp.Message
to be exact). I have the following test:
import {Message} from 'amqplib/callback_api'
import { createMock } from "ts-auto-mock";
describe('reuse', () => {
let mock: Message;
beforeEach(() => {
mock = createMock<Message>();
});
it('should assign the value', () => {
expect(mock.content).toBe("");
});
});
This test (and whole project) is taken from your examples.
And I still have this message:
Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/--path-to-project--/reuse/1.test.ts:217
: { get: function () { return _sundefined || (_sundefined = undefined); }, set: function (_undefined) { _sundefined = _undefined; }, enumerable: true },
^
SyntaxError: Unexpected token :
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
Any idea how to resolve it?
Requirements list [email protected] as dependency. Looking at the package.json ts-jest@^26 is listed as devDependency so I'm guessing this supports jest >=24. If that's the case then the readme should be updated
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.