Testing two environments with jest

EDIT (Jan 2018): It is now possible to do so (since Jest v20), and the option is called projects. Read more about it the docs. Basically you can define an array of your projects you want Jest to be run within: { “projects”: [“<rootDir>/client”, “<rootDir>/server”, “<rootDir>/some-glob/*”] } Just remember every project needs to have its … Read more

vscode automatic type acquisition for jest

You have a few options in this case: Add jest to your package.json: “dependencies”: { “jest”: “^18.1.0” } This only works if you are working JavaScript and do not have a tsconfig.json. Install @types/jest $ npm install -D @types/jest This should work for both JavaScript and TypeScript projects. However @types but may be disabled by … Read more

How to exclude specific files in typescript only for the build?

One possible solution would be to use two different tsconfig files, one for the tests and one for the production build. tsconfig.json { “compilerOptions”: { “module”: “commonjs”, “target”: “es6”, “outDir”: “./build”, “baseUrl”: “.”, “paths”: { “*”: [“types/*”] }, “strict”: true, } } tsconfig.prod.json { “extends”: “./tsconfig”, “exclude”: [“**/*.test.ts”, “**/*.mock.ts”] } Then point tsc to the … Read more

Testing Observables with jest

There are some good examples in the Jest documentation about passing in an argument for the test. This argument can be called to signal a passing test or you can call fail on it to fail the test, or it can timeout and fail. https://jestjs.io/docs/en/asynchronous.html https://alligator.io/testing/asynchronous-testing-jest/ Examples Notice I set the timeout to 1500ms const … Read more

JEST Received function did not throw, but HTTPError is thrown

expect(…).toThrow() is for checking if an error is thrown from a function call. When calling an async function, it never throws an error; rather it returns a Promise which may eventually become “rejected.” Although async functions use the same throw/catch terminology, the code required to detect a thrown error differs from what’s required to detect … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)