Coder Social home page Coder Social logo

typescript-tdd / jest-ts-auto-mock Goto Github PK

View Code? Open in Web Editor NEW
168.0 168.0 13.0 876 KB

Jest test utility with automatic mock creation for interfaces and classes

JavaScript 43.07% TypeScript 56.93%
fake jest-mock mock mock-interface mock-typescript testing typescript-transformer

jest-ts-auto-mock's People

Contributors

afonsojramos avatar boginw avatar dependabot[bot] avatar greenkeeper[bot] avatar okuuva avatar qdelettre avatar uittorio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

jest-ts-auto-mock's Issues

Example does not work

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)

Uses an old version of ts-auto-mock

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. :)

Support for Typescript 4

Requirements list typescript@^3.2.2 as dependency. Is there any plans on supporting typescript@^4?

Add support for Jest 28

Hey,

are there any plans to support jest 28?
Also, is there any roadmap/plans for newer versions of the lib?

the config for setupfiles doesnt work

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

TypeError: Cannot read property 'ids' of undefined, help needed

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?

Jest encountered an unexpected token, help needed

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.