ts-jest

React Jest test fails to run with ts-jest - Encountered an unexpected token on imported file

余生颓废 提交于 2020-06-27 08:40:49
问题 I'm new to testing React/Typescript apps. I want to unit test my React components, because I'm not satisfied to develop apps without tests at all. The app itself works fine, it's just failing to run in test mode. command (alias for react-scripts test ): yarn test output: FAIL src/containers/pages/Feature/Feature.test.tsx ● 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

Angular Spectator setInput not working for non-string input

此生再无相见时 提交于 2020-06-16 18:01:10
问题 I've successfully converted my project to use Jest in place of Karma/Jasmine and I have lots of tests that are working just fine. I'm trying to do what should be a very simple test using Spectator (^5.2.1) but it's not working. I'm trying to test a library component that uses mat-table to render a table. Inputs are title:string, columns: BehaviorSubject<MyColumnDefType> | MyColumnDefType[], dataSource: MyDataSource | any[] The component works fine, and all my other tests work, up until I

Angular Spectator setInput not working for non-string input

有些话、适合烂在心里 提交于 2020-06-16 18:00:20
问题 I've successfully converted my project to use Jest in place of Karma/Jasmine and I have lots of tests that are working just fine. I'm trying to do what should be a very simple test using Spectator (^5.2.1) but it's not working. I'm trying to test a library component that uses mat-table to render a table. Inputs are title:string, columns: BehaviorSubject<MyColumnDefType> | MyColumnDefType[], dataSource: MyDataSource | any[] The component works fine, and all my other tests work, up until I

“SyntaxError: Cannot use import statement outside a module” when writing test with typescript with lit-html

孤者浪人 提交于 2020-06-16 04:16:29
问题 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`<h1>Hello ${name}</h1>`; } and use jest to write some simple test: import sayHello from "./sayHello"; import {render} from "lit-html"; beforeEach(() => { render('', document.body); }) describe('sayHello', () => { it('says hello', () => { render(sayHello('world'), document.body); const component = document

Order of functions being executed in Express messed with tests

泪湿孤枕 提交于 2020-04-18 05:47:47
问题 I was trying to integrate Jest and Supertest to build integration tests on some middleware. I generated my middleware functions dynamically as they varied route to route, and the look like this: export function middleware1(param: paramType) { return async (req: Request, res: Response, next: NextFunction) => { ... }; } In my Jest tests, at the top of the file, I mock middleware1 as so: jest.mock('../middleware_path', () => ({ middleware1: jest.fn( _ => { return (req, res, next) => { return new

Order of functions being executed in Express messed with tests

自作多情 提交于 2020-04-18 03:48:36
问题 I was trying to integrate Jest and Supertest to build integration tests on some middleware. I generated my middleware functions dynamically as they varied route to route, and the look like this: export function middleware1(param: paramType) { return async (req: Request, res: Response, next: NextFunction) => { ... }; } In my Jest tests, at the top of the file, I mock middleware1 as so: jest.mock('../middleware_path', () => ({ middleware1: jest.fn( _ => { return (req, res, next) => { return new

Order of functions being executed in Express messed with tests

时光总嘲笑我的痴心妄想 提交于 2020-04-18 03:47:06
问题 I was trying to integrate Jest and Supertest to build integration tests on some middleware. I generated my middleware functions dynamically as they varied route to route, and the look like this: export function middleware1(param: paramType) { return async (req: Request, res: Response, next: NextFunction) => { ... }; } In my Jest tests, at the top of the file, I mock middleware1 as so: jest.mock('../middleware_path', () => ({ middleware1: jest.fn( _ => { return (req, res, next) => { return new

How to resolve “Cannot use import statement outside a module” in jest

ぃ、小莉子 提交于 2020-03-18 04:38:05
问题 I have a React application (not using Create React App) built using TypeScript, Jest, Webpack, and Babel. When trying to run "yarn jest", I get the following error: I have tried removing all packages and re-adding them. It does not resolve this. I have looked at similar questions and documentation and am still misunderstanding something. I went so far as to follow another guide for setting up this environment from scratch and still received this issue with my code. Dependencies include...

Angular Testing - Using Jest with Protractor

不想你离开。 提交于 2020-03-05 05:16:08
问题 I am new to Angular testing, and I want to perform 2 kinds of test for my application: Unit Test - I choose to use Jest since I can run my test without opening the browser, and it also supports testing for specific cases with --testNamePatern . End to end test - I want to try out Protractor since it is available in Angular and also has a big Angular community to work with. My question is, can I use both Jest and Protractor in my application? If yes, do I need to configure anything to use both

How to let know typescript compiler about jest custom matchers?

懵懂的女人 提交于 2020-02-24 03:43:08
问题 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: Brand, expected: RemoteBrand) { const pass: boolean = attributesMatch(actual, expected); const message: string = pass ? 'Local matches Remote' : 'Local does not match Remote'; return { pass, message: () => message }; } }; } }; which I reference in my tests by doing inside