Angular 2 and jQuery - how to test?

前端 未结 1 1893
眼角桃花
眼角桃花 2020-12-31 04:03

I am using Angular-CLI (webpack version) for my Angular 2 project and I also need to use jQuery (sadly. In my case, it\'s a dependency of Semantic-UI and I am using it for h

相关标签:
1条回答
  • 2020-12-31 04:30

    This is because the testing html file, provided by Karma, doesn't include the scripts.bundle.js file as normally served version does.

    The solution is easy; you just include same path to the jquery file into karma.config.js file in project's root folder. This file is available at the root of the project.

    In files array, add the path with watched flag like this:

    files: [
      { pattern: './node_modules/jquery/dist/jquery.min.js', watched: false },    
      { pattern: './src/test.ts', watched: false }
    ]
    

    Karma now should know about the jQuery dependency.

    0 讨论(0)
提交回复
热议问题