Unit testing using Jasmine and TypeScript

后端 未结 7 2008
一生所求
一生所求 2021-01-31 01:26

I am trying to get a unit test written in Typescript using Jasmine to compile. With the following in my unit-test file, Resharper prompts me with a link to import types from jas

7条回答
  •  孤城傲影
    2021-01-31 02:29

    If you have issues with imports, use tsconfig-paths

    npm i ts-node tsconfig-paths types/jasmine jasmine --save-dev
    

    Run typescript-enabled jasmine:

    ts-node -r tsconfig-paths/register node_modules/jasmine/bin/jasmine.js
    

    Ensure that your jasmine will search .ts files:

    "spec_files": [
        "**/*[sS]pec.ts"
    ],
    "helpers": [
        "helpers/**/*.ts"
    ],
    

    To test your scripts you may also need polyfills if you use them in your project. Create a helper file with required imports, like helpers/global/polifill.ts

    import 'core-js';
    

提交回复
热议问题