Skip to content

Commit 0a7beca

Browse files
committed
fix unit tests and jsdom usage
1 parent da77599 commit 0a7beca

File tree

5 files changed

+125
-17
lines changed

5 files changed

+125
-17
lines changed

draft-js-plugins-editor/src/Editor/__test__/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ describe('Editor', () => {
501501
expect(pluginEditor.resolveblockRenderMap()).to.deep.equal(expected);
502502
});
503503

504-
it.skip('returns the component reference when we call the getEditorRef inside of a plugin', () => {
504+
it('returns the component reference when we call the getEditorRef inside of a plugin', () => {
505505
const spy = sinon.spy();
506506
const plugins = [{
507507
onChange: (state, pluginFunctions) => spy(pluginFunctions.getEditorRef())
@@ -630,7 +630,7 @@ describe('Editor', () => {
630630
decorators = [decorator];
631631
});
632632

633-
it.skip('uses strategies from both decorators and plugins together', () => {
633+
it('uses strategies from both decorators and plugins together', () => {
634634
const pluginStrategy = sinon.spy(plugin.decorators[0], 'strategy');
635635
const decoratorStrategy = sinon.spy(decorator, 'strategy');
636636

@@ -640,13 +640,13 @@ describe('Editor', () => {
640640
expect(pluginStrategy).has.been.called();
641641
});
642642

643-
it.skip('uses components from both decorators and plugins together', () => {
643+
it('uses components from both decorators and plugins together', () => {
644644
const pluginComponent = sinon.spy(plugin.decorators[0], 'component');
645645
const decoratorComponent = sinon.spy(decorator, 'component');
646646

647647
const wrapper = mount(<TestEditor {...{ plugins, decorators, text }} />);
648-
const decoratorComponents = wrapper.findWhere((n) => n.hasClass('decorator'));
649-
const pluginComponents = wrapper.findWhere((n) => n.hasClass('plugin'));
648+
const decoratorComponents = wrapper.find('.decorator');
649+
const pluginComponents = wrapper.find('.plugin');
650650

651651
expect(decoratorComponent).has.been.called();
652652
expect(pluginComponent).has.been.called();

draft-js-plugins-editor/src/utils/createEditorStateWithText.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ import {
77
EditorState,
88
} from 'draft-js';
99

10-
export default (text) => EditorState.createWithContent(ContentState.createFromText(text));
10+
export default (text) => EditorState.createWithContent(
11+
ContentState.createFromText(text)
12+
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"extract-text-webpack-plugin": "^2.0.0",
7373
"flow-bin": "^0.40.0",
7474
"jest-cli": "^18.1.0",
75-
"jsdom": "^9.11.0",
75+
"jsdom": "^11.3.0",
7676
"lint-staged": "^3.3.1",
7777
"mocha": "^3.0.2",
7878
"multer": "^1.3.0",

testHelper.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
11
import chai from 'chai';
22
import dirtyChai from 'dirty-chai';
33
import hook from 'css-modules-require-hook';
4-
import { jsdom } from 'jsdom';
54

65
process.env.NODE_ENV = 'test';
76

87
hook({
98
generateScopedName: '[name]__[local]___[hash:base64:5]',
109
});
1110

11+
const { JSDOM } = require('jsdom');
12+
13+
const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
14+
const { window } = jsdom;
15+
16+
function copyProps(src, target) {
17+
const props = Object.getOwnPropertyNames(src)
18+
.filter(prop => typeof target[prop] === 'undefined')
19+
.reduce((result, prop) => ({
20+
...result,
21+
[prop]: Object.getOwnPropertyDescriptor(src, prop),
22+
}), {});
23+
Object.defineProperties(target, props);
24+
}
25+
26+
global.window = window;
27+
global.document = window.document;
28+
global.navigator = {
29+
userAgent: 'node.js',
30+
};
31+
copyProps(window, global);
32+
1233
const exposedProperties = ['window', 'navigator', 'document'];
1334

14-
global.document = jsdom('');
15-
global.window = document.defaultView;
1635
Object.keys(document.defaultView).forEach((property) => {
1736
if (typeof global[property] === 'undefined') {
1837
exposedProperties.push(property);

yarn.lock

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@
145145
version "3.0.1"
146146
resolved "https://registry.yarnpkg.com/@types/inline-style-prefixer/-/inline-style-prefixer-3.0.1.tgz#8541e636b029124b747952e9a28848286d2b5bf6"
147147

148+
"@types/node@*":
149+
version "8.0.50"
150+
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.50.tgz#dc545448e128c88c4eec7cd64025fcc3b7604541"
151+
148152
"@types/react@^16.0.18":
149153
version "16.0.22"
150154
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.0.22.tgz#19ad106e124aceebd2b4d430a278d55413ee8759"
@@ -176,6 +180,12 @@ acorn-globals@^3.1.0:
176180
dependencies:
177181
acorn "^4.0.4"
178182

183+
acorn-globals@^4.0.0:
184+
version "4.1.0"
185+
resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-4.1.0.tgz#ab716025dbe17c54d3ef81d32ece2b2d99fe2538"
186+
dependencies:
187+
acorn "^5.0.0"
188+
179189
acorn-jsx@^3.0.0:
180190
version "3.0.1"
181191
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-3.0.1.tgz#afdf9488fb1ecefc8348f6fb22f464e32a58b36b"
@@ -190,7 +200,7 @@ acorn@^4.0.3, acorn@^4.0.4:
190200
version "4.0.13"
191201
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787"
192202

193-
acorn@^5.0.0, acorn@^5.1.1:
203+
acorn@^5.0.0, acorn@^5.1.1, acorn@^5.1.2:
194204
version "5.2.1"
195205
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.2.1.tgz#317ac7821826c22c702d66189ab8359675f135d7"
196206

@@ -2715,6 +2725,10 @@ domelementtype@~1.1.1:
27152725
version "1.1.3"
27162726
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.1.3.tgz#bd28773e2642881aec51544924299c5cd822185b"
27172727

2728+
domexception@^1.0.0:
2729+
version "1.0.0"
2730+
resolved "https://registry.yarnpkg.com/domexception/-/domexception-1.0.0.tgz#81fe5df81b3f057052cde3a9fa9bf536a85b9ab0"
2731+
27182732
domhandler@^2.3.0:
27192733
version "2.4.1"
27202734
resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-2.4.1.tgz#892e47000a99be55bbf3774ffea0561d8879c259"
@@ -2960,7 +2974,7 @@ [email protected], escape-string-regexp@^1.0.2, escape-string-regexp@^1
29602974
version "1.0.5"
29612975
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
29622976

2963-
escodegen@^1.6.1:
2977+
escodegen@^1.6.1, escodegen@^1.9.0:
29642978
version "1.9.0"
29652979
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.9.0.tgz#9811a2f265dc1cd3894420ee3717064b632b8852"
29662980
dependencies:
@@ -4615,7 +4629,34 @@ jsbn@~0.1.0:
46154629
version "0.1.1"
46164630
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
46174631

4618-
jsdom@^9.11.0, jsdom@^9.9.1:
4632+
jsdom@^11.3.0:
4633+
version "11.3.0"
4634+
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-11.3.0.tgz#7b2dfe6227d014084d80f6b3e98fa1e4cef199e7"
4635+
dependencies:
4636+
abab "^1.0.3"
4637+
acorn "^5.1.2"
4638+
acorn-globals "^4.0.0"
4639+
array-equal "^1.0.0"
4640+
content-type-parser "^1.0.1"
4641+
cssom ">= 0.3.2 < 0.4.0"
4642+
cssstyle ">= 0.2.37 < 0.3.0"
4643+
domexception "^1.0.0"
4644+
escodegen "^1.9.0"
4645+
html-encoding-sniffer "^1.0.1"
4646+
nwmatcher "^1.4.1"
4647+
parse5 "^3.0.2"
4648+
pn "^1.0.0"
4649+
request "^2.83.0"
4650+
request-promise-native "^1.0.3"
4651+
sax "^1.2.1"
4652+
symbol-tree "^3.2.1"
4653+
tough-cookie "^2.3.3"
4654+
webidl-conversions "^4.0.2"
4655+
whatwg-encoding "^1.0.1"
4656+
whatwg-url "^6.3.0"
4657+
xml-name-validator "^2.0.1"
4658+
4659+
jsdom@^9.9.1:
46194660
version "9.12.0"
46204661
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-9.12.0.tgz#e8c546fffcb06c00d4833ca84410fed7f8a097d4"
46214662
dependencies:
@@ -5055,7 +5096,7 @@ lodash.uniq@^4.5.0:
50555096
version "4.5.0"
50565097
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
50575098

5058-
[email protected], lodash@^4.0.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.17.4, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.6.1:
5099+
[email protected], lodash@^4.0.0, lodash@^4.11.1, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.17.4, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.6.1:
50595100
version "4.17.4"
50605101
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
50615102

@@ -5557,7 +5598,7 @@ number-is-nan@^1.0.0:
55575598
version "1.0.1"
55585599
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
55595600

5560-
"nwmatcher@>= 1.3.9 < 2.0.0":
5601+
"nwmatcher@>= 1.3.9 < 2.0.0", nwmatcher@^1.4.1:
55615602
version "1.4.3"
55625603
resolved "https://registry.yarnpkg.com/nwmatcher/-/nwmatcher-1.4.3.tgz#64348e3b3d80f035b40ac11563d278f8b72db89c"
55635604

@@ -5801,6 +5842,12 @@ parse5@^1.5.1:
58015842
version "1.5.1"
58025843
resolved "https://registry.yarnpkg.com/parse5/-/parse5-1.5.1.tgz#9b7f3b0de32be78dc2401b17573ccaf0f6f59d94"
58035844

5845+
parse5@^3.0.2:
5846+
version "3.0.3"
5847+
resolved "https://registry.yarnpkg.com/parse5/-/parse5-3.0.3.tgz#042f792ffdd36851551cf4e9e066b3874ab45b5c"
5848+
dependencies:
5849+
"@types/node" "*"
5850+
58045851
parseurl@~1.3.2:
58055852
version "1.3.2"
58065853
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3"
@@ -5915,6 +5962,10 @@ pluralize@^7.0.0:
59155962
version "7.0.0"
59165963
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"
59175964

5965+
pn@^1.0.0:
5966+
version "1.0.0"
5967+
resolved "https://registry.yarnpkg.com/pn/-/pn-1.0.0.tgz#1cf5a30b0d806cd18f88fc41a6b5d4ad615b3ba9"
5968+
59185969
podda@^1.2.2:
59195970
version "1.2.2"
59205971
resolved "https://registry.yarnpkg.com/podda/-/podda-1.2.2.tgz#15b0edbd334ade145813343f5ecf9c10a71cf500"
@@ -6349,6 +6400,10 @@ punycode@^1.2.4, punycode@^1.4.1:
63496400
version "1.4.1"
63506401
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"
63516402

6403+
punycode@^2.1.0:
6404+
version "2.1.0"
6405+
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.0.tgz#5f863edc89b96db09074bad7947bf09056ca4e7d"
6406+
63526407
q@^1.1.2:
63536408
version "1.5.1"
63546409
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
@@ -6906,6 +6961,20 @@ [email protected]:
69066961
version "1.0.0"
69076962
resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-1.0.0.tgz#de63128373fcbf7c3ccfa4de5a480c45a67958eb"
69086963

6964+
6965+
version "1.1.1"
6966+
resolved "https://registry.yarnpkg.com/request-promise-core/-/request-promise-core-1.1.1.tgz#3eee00b2c5aa83239cfb04c5700da36f81cd08b6"
6967+
dependencies:
6968+
lodash "^4.13.1"
6969+
6970+
request-promise-native@^1.0.3:
6971+
version "1.0.5"
6972+
resolved "https://registry.yarnpkg.com/request-promise-native/-/request-promise-native-1.0.5.tgz#5281770f68e0c9719e5163fd3fab482215f4fda5"
6973+
dependencies:
6974+
request-promise-core "1.1.1"
6975+
stealthy-require "^1.1.0"
6976+
tough-cookie ">=2.3.3"
6977+
69096978
69106979
version "2.81.0"
69116980
resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0"
@@ -7390,6 +7459,10 @@ statuses@~1.3.1:
73907459
version "1.3.1"
73917460
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"
73927461

7462+
stealthy-require@^1.1.0:
7463+
version "1.1.1"
7464+
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
7465+
73937466
stream-browserify@^2.0.1:
73947467
version "2.0.1"
73957468
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.1.tgz#66266ee5f9bdb9940a4e4514cafb43bb71e5c9db"
@@ -7736,12 +7809,18 @@ to-vfile@^2.0.0:
77367809
is-buffer "^1.1.4"
77377810
vfile "^2.0.0"
77387811

7739-
tough-cookie@^2.3.2, tough-cookie@~2.3.0, tough-cookie@~2.3.3:
7812+
tough-cookie@>=2.3.3, tough-cookie@^2.3.2, tough-cookie@^2.3.3, tough-cookie@~2.3.0, tough-cookie@~2.3.3:
77407813
version "2.3.3"
77417814
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.3.tgz#0b618a5565b6dea90bf3425d04d55edc475a7561"
77427815
dependencies:
77437816
punycode "^1.4.1"
77447817

7818+
tr46@^1.0.0:
7819+
version "1.0.1"
7820+
resolved "https://registry.yarnpkg.com/tr46/-/tr46-1.0.1.tgz#a8b13fd6bfd2489519674ccde55ba3693b706d09"
7821+
dependencies:
7822+
punycode "^2.1.0"
7823+
77457824
tr46@~0.0.3:
77467825
version "0.0.3"
77477826
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
@@ -8138,7 +8217,7 @@ webidl-conversions@^3.0.0:
81388217
version "3.0.1"
81398218
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
81408219

8141-
webidl-conversions@^4.0.0:
8220+
webidl-conversions@^4.0.0, webidl-conversions@^4.0.1, webidl-conversions@^4.0.2:
81428221
version "4.0.2"
81438222
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"
81448223

@@ -8238,6 +8317,14 @@ whatwg-url@^4.3.0:
82388317
tr46 "~0.0.3"
82398318
webidl-conversions "^3.0.0"
82408319

8320+
whatwg-url@^6.3.0:
8321+
version "6.3.0"
8322+
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.3.0.tgz#597ee5488371abe7922c843397ddec1ae94c048d"
8323+
dependencies:
8324+
lodash.sortby "^4.7.0"
8325+
tr46 "^1.0.0"
8326+
webidl-conversions "^4.0.1"
8327+
82418328
whet.extend@~0.9.9:
82428329
version "0.9.9"
82438330
resolved "https://registry.yarnpkg.com/whet.extend/-/whet.extend-0.9.9.tgz#f877d5bf648c97e5aa542fadc16d6a259b9c11a1"

0 commit comments

Comments
 (0)