我使用角CLI(的WebPack版本)我的角2的項目,我也需要使用jQuery(可悲的。對我來說,這是語義的UI的依賴,我用它來處理菜單下拉菜單)。Angular 2和jQuery - 如何測試?
的方式我使用它:
npm install jquery --save
然後在它上市angular-cli.json
文件scripts
數組中:
scripts": [
"../node_modules/jquery/dist/jquery.min.js"
]
所以它被納入包文件,該文件被自動用於根html文件:
<script type="text/javascript" src="scripts.bundle.js">
然後declare var $: any;
在我需要的文件中,它運行良好。
但是,ng test
測試存在問題,因爲Karma引發錯誤$ is not defined
。
你怎麼包括jQuery的在組件的規格?我得到了同樣的錯誤,並嘗試通過karma.conf.js中的文件數組包含jQuery。 –