ts-jest

NestJS Jest cannot find module with absolute path

余生长醉 提交于 2021-02-17 01:56:28
问题 I have a quite new NestJS application. I'm trying to run unit tests, but they keep failing due to 'cannot find module..' when using absolute paths ("src/users/..."), but works when using relative paths ("./users/.."). Is there anything wrong with my configuration here? Jest setup in package.json: "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "rootDir": "src", "testRegex": ".spec.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" }, "coverageDirectory": "../coverage", "testEnvironment

How to get a Jest custom matcher working in typescript?

旧时模样 提交于 2021-02-07 11:49:19
问题 I regularly have unit tests where I need to compare two moment objects. I'd us moment's built-in function moment.isSame(moment) to compare them. However, this means my assertion will look like this: expect(moment1.isSame(moment2)).toBeTrue(); I didn't quite like this, especially because the failure message will be less informative. Hence, I wanted to write a custom jest matcher "toBeSameMoment". The following code seems to compile at least: import moment from "moment"; declare global {

How to get a Jest custom matcher working in typescript?

烈酒焚心 提交于 2021-02-07 11:48:43
问题 I regularly have unit tests where I need to compare two moment objects. I'd us moment's built-in function moment.isSame(moment) to compare them. However, this means my assertion will look like this: expect(moment1.isSame(moment2)).toBeTrue(); I didn't quite like this, especially because the failure message will be less informative. Hence, I wanted to write a custom jest matcher "toBeSameMoment". The following code seems to compile at least: import moment from "moment"; declare global {

How to use jest.spyOn with React function component using Typescript

戏子无情 提交于 2020-12-10 08:48:06
问题 I am developing a React app using Typescript, and hooks, and I am trying to use Enzyme with Jest to test the function components. I am unable to use jest.spyOn to test a method in my component. The jest.spyOn method doesn't resolve correctly and shows following message on hover "Argument of type '"validateBeforeSave"' is not assignable to parameter of type '"context" | "setState" | "forceUpdate" | "render" | "componentDidMount" | "shouldComponentUpdate" | "componentWillUnmount" |

Typeorm Connection “default” was not found when connection is created in jest globalSetup

…衆ロ難τιáo~ 提交于 2020-07-10 05:18:13
问题 I'm having a similar problem as in #5164 and this question. Consider the following working test code: // AccountResolver.test.ts describe('Account entity', () => { it('add account', async () => { await createConnections() const defaultConnection = getConnection('default') const actual = await callGraphql( `mutation { addAccount(options: { accountIdentifier: "7csdcd8-8a5f-49c3-ab9a-0198d42dd253" name: "Jake, Bob (Braine-l’Alleud) JAM" userName: "Bob.Marley@contoso.com" }) { accountIdentifier

Typeorm Connection “default” was not found when connection is created in jest globalSetup

早过忘川 提交于 2020-07-10 05:16:48
问题 I'm having a similar problem as in #5164 and this question. Consider the following working test code: // AccountResolver.test.ts describe('Account entity', () => { it('add account', async () => { await createConnections() const defaultConnection = getConnection('default') const actual = await callGraphql( `mutation { addAccount(options: { accountIdentifier: "7csdcd8-8a5f-49c3-ab9a-0198d42dd253" name: "Jake, Bob (Braine-l’Alleud) JAM" userName: "Bob.Marley@contoso.com" }) { accountIdentifier

Typeorm Connection “default” was not found when connection is created in jest globalSetup

旧时模样 提交于 2020-07-10 05:16:10
问题 I'm having a similar problem as in #5164 and this question. Consider the following working test code: // AccountResolver.test.ts describe('Account entity', () => { it('add account', async () => { await createConnections() const defaultConnection = getConnection('default') const actual = await callGraphql( `mutation { addAccount(options: { accountIdentifier: "7csdcd8-8a5f-49c3-ab9a-0198d42dd253" name: "Jake, Bob (Braine-l’Alleud) JAM" userName: "Bob.Marley@contoso.com" }) { accountIdentifier