Questions tagged [ts-jest]
451 questions
7
votes
1 answer
Configure jest timeout once for all tests
According to the docs one can increase the default async timeout from 5000ms using the jest-object
More specifically, by using the jestsettimeouttimeout
The issue I am facing is I am running a series of tests against an API that is very slow, 5-15…
John
- 4,512
- 8
- 48
- 98
7
votes
3 answers
How to use jest.spyOn with React function component using Typescript
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…
codermav
- 185
- 1
- 8
6
votes
1 answer
Typeorm decorator is not a function
I have the following controller that I want to test :
class Album {
public static getAlbums(): Promise {
return getRepository(AlbumModel).find({ relations: ['pictures'] });
}
}
Which is linked to a model, i'm using typeorm…
TLd
- 165
- 14
6
votes
1 answer
How to let TypeScript know about custom Jest matchers?
I have a react/typescript project, using jest, where I have a custom matcher like:
export const MyCustomMatchers = {
toBeTheSameAsRemote: function(_util: any, _customEqualityTesters: any) {
return {
compare: function(actual:…
johncol
- 444
- 6
- 11
6
votes
3 answers
React Jest test fails to run with ts-jest - Unexpected token on imported file
I have a test for a test for a TSX file written in a JSX file which fails to run due to unexpected token:
Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest…
Antfish
- 849
- 15
- 34
5
votes
1 answer
"SyntaxError: Cannot use import statement outside a module" when writing test with typescript with lit-html
I use typescript to write a simple demo with lit-html:
import {html, TemplateResult} from 'lit-html';
export default function sayHello(name: string): TemplateResult {
return html`
Hello ${name}
`; } and use jest to write some simple…
Freewind
- 177,284
- 143
- 381
- 649
5
votes
2 answers
Vuetify Jest Unknown custom element
I am writing unit tests for my project, using Jest. Project is based on Vue, Vuetify (1.5) and TypeScript (and vue-property-decorator).
I have basic wrapper for . It looks like this:
KingGary
- 450
- 3
- 15
5
votes
2 answers
How to pass in the done() parameter on an async jest test.each case
I'm trying write a jest test case that tests an async method, I want to pass in the done() parameter so jest waits for it to be fired before it ends the test, however, I'm not sure where to put it.
Any ideas?
const testcases = [
[
…
uneatenbreakfast
- 373
- 3
- 12
4
votes
1 answer
Migration from JS to TS, Jest doesn't see "globals"
I recently migrated my code base from JS to TS and everything is looking good so far.
The issue I am facing is that when I try to change the test file extensions to .ts or .tsx as needed, Jest no longer sees all my global variables and setup…
lbragile
- 3,410
- 3
- 15
- 36
4
votes
0 answers
Can't run jest tests on my react native application [React Native + TypeScript]
I'm trying to run tests on this project for the first time, but i having some problems with the modules, thats the error i'm having:
FAIL src/components/text/index.test.tsx
● Test suite failed to run
Cannot find module 'react' from…
Backes
- 41
- 1
4
votes
2 answers
Mocking AWS services and Lambda best practices
I'm working on a simple AWS lambda function which is triggered by DynamoDB Streams events and should forward all records except for REMOVE events to an SQS queue. The function works as expected, no surprises there.
I want to write a unit test to…
mheck
- 159
- 2
- 12
4
votes
2 answers
NestJS Jest cannot find module with absolute path
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…
Chris Eikrem
- 187
- 1
- 10
4
votes
0 answers
How to exclude files for compilation but include for testing in Typescript?
File structure
functions/lib/src/...src .ts files
functions/lib/test/...test files
functions/tsconfig.json
When I include test files directory in the tsconfig.json.include property linting works fine in my test files. However when I run tsc the…
jonnyc
- 117
- 4
4
votes
3 answers
Vscode TS language features unavailable when tests/** are not included in the tsconfig
I would like my typescript tests to receive linting, code completion, vscode intellisense (ts language features) when the test folder is adjacent to the src. I do NOT want the tests to transpile when I build my typescript project.
My typescript node…
Shahaed
- 115
- 1
- 10
4
votes
0 answers
TypeScript + Jest + Ts-Jest Error: error when run build script
When the script build is executed the prompt return a dependecies error:
> tsc -p tsconfig.json && rollup -c rollup.config.js
node_modules/@types/jest/index.d.ts:484:51 - error TS2307: Cannot find module 'jest-diff'.
484 diff(a: any,…
Felipe Sousa
- 43
- 4