Skip to content

Commit

Permalink
fix unit tests and jsdom usage
Browse files Browse the repository at this point in the history
  • Loading branch information
juliankrispel committed Nov 10, 2017
1 parent da77599 commit 0a7beca
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 17 deletions.
10 changes: 5 additions & 5 deletions draft-js-plugins-editor/src/Editor/__test__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ describe('Editor', () => {
expect(pluginEditor.resolveblockRenderMap()).to.deep.equal(expected);
});

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

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

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

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

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

expect(decoratorComponent).has.been.called();
expect(pluginComponent).has.been.called();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ import {
EditorState,
} from 'draft-js';

export default (text) => EditorState.createWithContent(ContentState.createFromText(text));
export default (text) => EditorState.createWithContent(
ContentState.createFromText(text)
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"extract-text-webpack-plugin": "^2.0.0",
"flow-bin": "^0.40.0",
"jest-cli": "^18.1.0",
"jsdom": "^9.11.0",
"jsdom": "^11.3.0",
"lint-staged": "^3.3.1",
"mocha": "^3.0.2",
"multer": "^1.3.0",
Expand Down
25 changes: 22 additions & 3 deletions testHelper.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import chai from 'chai';
import dirtyChai from 'dirty-chai';
import hook from 'css-modules-require-hook';
import { jsdom } from 'jsdom';

process.env.NODE_ENV = 'test';

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

const { JSDOM } = require('jsdom');

const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;

function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.reduce((result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop),
}), {});
Object.defineProperties(target, props);
}

global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};
copyProps(window, global);

const exposedProperties = ['window', 'navigator', 'document'];

global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
Expand Down
101 changes: 94 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@
version "3.0.1"
resolved "https://registry.yarnpkg.com/@types/inline-style-prefixer/-/inline-style-prefixer-3.0.1.tgz#8541e636b029124b747952e9a28848286d2b5bf6"

"@types/node@*":
version "8.0.50"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.50.tgz#dc545448e128c88c4eec7cd64025fcc3b7604541"

"@types/react@^16.0.18":
version "16.0.22"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.0.22.tgz#19ad106e124aceebd2b4d430a278d55413ee8759"
Expand Down Expand Up @@ -176,6 +180,12 @@ acorn-globals@^3.1.0:
dependencies:
acorn "^4.0.4"

acorn-globals@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-4.1.0.tgz#ab716025dbe17c54d3ef81d32ece2b2d99fe2538"
dependencies:
acorn "^5.0.0"

acorn-jsx@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-3.0.1.tgz#afdf9488fb1ecefc8348f6fb22f464e32a58b36b"
Expand All @@ -190,7 +200,7 @@ acorn@^4.0.3, acorn@^4.0.4:
version "4.0.13"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787"

acorn@^5.0.0, acorn@^5.1.1:
acorn@^5.0.0, acorn@^5.1.1, acorn@^5.1.2:
version "5.2.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.2.1.tgz#317ac7821826c22c702d66189ab8359675f135d7"

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

domexception@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/domexception/-/domexception-1.0.0.tgz#81fe5df81b3f057052cde3a9fa9bf536a85b9ab0"

domhandler@^2.3.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-2.4.1.tgz#892e47000a99be55bbf3774ffea0561d8879c259"
Expand Down Expand Up @@ -2960,7 +2974,7 @@ [email protected], escape-string-regexp@^1.0.2, escape-string-regexp@^1
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"

escodegen@^1.6.1:
escodegen@^1.6.1, escodegen@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.9.0.tgz#9811a2f265dc1cd3894420ee3717064b632b8852"
dependencies:
Expand Down Expand Up @@ -4615,7 +4629,34 @@ jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"

jsdom@^9.11.0, jsdom@^9.9.1:
jsdom@^11.3.0:
version "11.3.0"
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-11.3.0.tgz#7b2dfe6227d014084d80f6b3e98fa1e4cef199e7"
dependencies:
abab "^1.0.3"
acorn "^5.1.2"
acorn-globals "^4.0.0"
array-equal "^1.0.0"
content-type-parser "^1.0.1"
cssom ">= 0.3.2 < 0.4.0"
cssstyle ">= 0.2.37 < 0.3.0"
domexception "^1.0.0"
escodegen "^1.9.0"
html-encoding-sniffer "^1.0.1"
nwmatcher "^1.4.1"
parse5 "^3.0.2"
pn "^1.0.0"
request "^2.83.0"
request-promise-native "^1.0.3"
sax "^1.2.1"
symbol-tree "^3.2.1"
tough-cookie "^2.3.3"
webidl-conversions "^4.0.2"
whatwg-encoding "^1.0.1"
whatwg-url "^6.3.0"
xml-name-validator "^2.0.1"

jsdom@^9.9.1:
version "9.12.0"
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-9.12.0.tgz#e8c546fffcb06c00d4833ca84410fed7f8a097d4"
dependencies:
Expand Down Expand Up @@ -5055,7 +5096,7 @@ lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"

[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:
[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:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"

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

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

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

parse5@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/parse5/-/parse5-3.0.3.tgz#042f792ffdd36851551cf4e9e066b3874ab45b5c"
dependencies:
"@types/node" "*"

parseurl@~1.3.2:
version "1.3.2"
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.2.tgz#fc289d4ed8993119460c156253262cdc8de65bf3"
Expand Down Expand Up @@ -5915,6 +5962,10 @@ pluralize@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"

pn@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/pn/-/pn-1.0.0.tgz#1cf5a30b0d806cd18f88fc41a6b5d4ad615b3ba9"

podda@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/podda/-/podda-1.2.2.tgz#15b0edbd334ade145813343f5ecf9c10a71cf500"
Expand Down Expand Up @@ -6349,6 +6400,10 @@ punycode@^1.2.4, punycode@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e"

punycode@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.0.tgz#5f863edc89b96db09074bad7947bf09056ca4e7d"

q@^1.1.2:
version "1.5.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
Expand Down Expand Up @@ -6906,6 +6961,20 @@ [email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/replace-ext/-/replace-ext-1.0.0.tgz#de63128373fcbf7c3ccfa4de5a480c45a67958eb"

[email protected]:
version "1.1.1"
resolved "https://registry.yarnpkg.com/request-promise-core/-/request-promise-core-1.1.1.tgz#3eee00b2c5aa83239cfb04c5700da36f81cd08b6"
dependencies:
lodash "^4.13.1"

request-promise-native@^1.0.3:
version "1.0.5"
resolved "https://registry.yarnpkg.com/request-promise-native/-/request-promise-native-1.0.5.tgz#5281770f68e0c9719e5163fd3fab482215f4fda5"
dependencies:
request-promise-core "1.1.1"
stealthy-require "^1.1.0"
tough-cookie ">=2.3.3"

[email protected]:
version "2.81.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0"
Expand Down Expand Up @@ -7390,6 +7459,10 @@ statuses@~1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.3.1.tgz#faf51b9eb74aaef3b3acf4ad5f61abf24cb7b93e"

stealthy-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"

stream-browserify@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.1.tgz#66266ee5f9bdb9940a4e4514cafb43bb71e5c9db"
Expand Down Expand Up @@ -7736,12 +7809,18 @@ to-vfile@^2.0.0:
is-buffer "^1.1.4"
vfile "^2.0.0"

tough-cookie@^2.3.2, tough-cookie@~2.3.0, tough-cookie@~2.3.3:
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:
version "2.3.3"
resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.3.tgz#0b618a5565b6dea90bf3425d04d55edc475a7561"
dependencies:
punycode "^1.4.1"

tr46@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-1.0.1.tgz#a8b13fd6bfd2489519674ccde55ba3693b706d09"
dependencies:
punycode "^2.1.0"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
Expand Down Expand Up @@ -8138,7 +8217,7 @@ webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"

webidl-conversions@^4.0.0:
webidl-conversions@^4.0.0, webidl-conversions@^4.0.1, webidl-conversions@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad"

Expand Down Expand Up @@ -8238,6 +8317,14 @@ whatwg-url@^4.3.0:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

whatwg-url@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.3.0.tgz#597ee5488371abe7922c843397ddec1ae94c048d"
dependencies:
lodash.sortby "^4.7.0"
tr46 "^1.0.0"
webidl-conversions "^4.0.1"

whet.extend@~0.9.9:
version "0.9.9"
resolved "https://registry.yarnpkg.com/whet.extend/-/whet.extend-0.9.9.tgz#f877d5bf648c97e5aa542fadc16d6a259b9c11a1"
Expand Down

0 comments on commit 0a7beca

Please sign in to comment.