无法在角度开玩笑之前加载jquery

时间:2018-08-01 14:23:00

标签: jquery angular jestjs

我正在尝试将业力茉莉花庞然大物转换为玩笑套件。到目前为止,我使用了jest-codemods,现在正尝试运行一个测试。我遇到了经典的[jqLite:nosel] Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element。我的jest.init.js看起来像这样:

console.log("Angular:", angular)

import $ from "jquery"
global.$ = global.jquery = global.jQuery = $
console.log("\n\n\n\n\njquery:", global.jquery )
import "babel-polyfill"
import "whatwg-fetch"

import app from '../js/angular/app.js'

var localStorageMock = {}
Object.defineProperty(window, 'localStorage', {
  value: localStorageMock
});

这是我开玩笑的配置:

module.exports = { testMatch: ['**/*Spec.js'], testURL: 'http://localhost', //setupTestFrameworkScriptFile: "<rootDir>/src/test/jest.init.js", setupFiles: ["<rootDir>/src/test/jest.init.js"], "transform": { "^.+\\.js$": "babel-jest", "^.+\\.html$": "<rootDir>/src/test/utils/htmlLoader.js" } }

现在它在setupFiles下运行,我以前在setupTestFrameworkScriptFile下有它(如您所见),我得到了相同的结果。

我已经看到了一些解决此问题的建议,包括将jquery注册到全局并确保首先使用带有Webpack的ProvidePlugin(我正在使用)加载jquery的方法,但是只要{{{ 1}}运行,但我不确定为什么。仅供参考,我正在使用

从命令行运行单个文件

jest.init.js文件开头的地方

jest --verbose src/js/angular/lastJob/lastJobSpec.js

我的问题是,为什么/在脚本之前在哪里加载角度?我是否可以访问较早的钩子以确保首先加载jquery?

0 个答案:

没有答案