次の実装があります。
import _ from 'lodash';
import test from 'tape';
import 'jsdom-global/register';
let jQuery = require('jquery')(window);
let $ = global.jQuery = jQuery;
test('check if Deferred work?', (t) => {
let dfd = $.Deferred();
let ajax = $.ajax();
console.log($.extend({}, {a: 1, b:2}), 'dfd', dfd, 'ajax', ajax);
t.equal(true, true, 'falsey condition');
t.end();
});
$ .extend作品が、dfd
とajax
ません。どのように私はそれを動作させることができますか?
エラーが読み取ります はTypeError:$ .Deferredは はTypeError関数ではありません:$アヤックスは
おかげ
EDIT関数ではありません。(可能な解決策が、私はびびるjsdomよ以下)は1日、非推奨jsdom.env()
のように壊れる場合、ライブラリの変更はそれほど頻繁に、IDK
const { JSDOM } = require('jsdom');
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;
import * as jquery from "jquery";
import test from 'tape';
import _ from 'lodash';
test("jquery tests", (t) => {
t.plan(2);
const $ = require("jquery")(window);
$.ajax({url: "http://freegeoip.net/json/"}).done(data => {
console.log("data is " + JSON.stringify(data));
t.equal(true, true);
t.ok(true);
t.end();
});
});
出力:
$ npx babel-tape-runner ./src/jquery-test.spec.es6.js
TAP version 13
# jquery tests
data is {"ip":"188.90.2xx.4","country_code":"US","country_name":"United States","region_code":"CA","region_name":"California","city":"Orange","zip_code":"92866","time_zone":"America/Los_Angeles","latitude":33.7846,"longitude":-117.8433,"metro_code":803}[object Object]
ok 1 should be equal
ok 2 should be truthy
jQueryを要求した後に '(ウィンドウ)'を削除してみてください。私はあなたがそれを必要としているとは思わないし、エラーを説明するだろう - あなたの 'jQuery'は実際にインスタンスです。あなたは 'console.log($)'と 'console.log(Object.keys($))'できますか? – Bergi