Skip to content

RouvenGonzalez/TypeScript-Tutorial

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypeScript-Tutorial

TypeScript Tutorial

Installing and configuring jest for TypeScript

  • In root folder of the project, install jest:
npm i -D jest
  • Installing types for TypeScript jest
npm i -D @types
  • Installing ts-test which compiles first and then run the tests
npm i -D ts-jest
  • Creating a file jest.config.js in the root of the project and pass this in it:
module.exports = {
   preset: 'ts-jest',
   testEnvironment: 'node',
   };
  • In package.json put this:
"scripts": {
    "test": "jest",
    "built": "tsc"
},
  • Create a test file named just like the file you want to test.
    • Example: the file we want to test: foo.ts
    • Example: the test file named: foo.test.ts

Testing the files

  • To see if the configuration is properly installed, just write a test like this:

    • In foo.ts
    export function boo(a, b) {
      return a + b;
    }
    
    • In foo.test.ts
    import { boo } from './foo';
    
    describe('Testing boo()', () => {
      it('boo(3, 5): return 8', () => {
        expect(boo(3, 5).toBe(8),
      }),
    });
    
  • Now run the test

run test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%