mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Merge branch '15-dev' into 15-stable
This commit is contained in:
commit
88296d994d
277 files changed
+12395
-19548
No files matched your search
+11
-11
@@ -1,13 +1,13 @@
|
||||
[ignore]
|
||||
|
||||
.*/examples/.*
|
||||
.*/build/.*
|
||||
.*/node_modules/y18n/.*
|
||||
.*/__mocks__/.*
|
||||
.*/__tests__/.*
|
||||
<PROJECT_ROOT>/examples/.*
|
||||
<PROJECT_ROOT>/build/.*
|
||||
<PROJECT_ROOT>/.*/node_modules/y18n/.*
|
||||
<PROJECT_ROOT>/.*/__mocks__/.*
|
||||
<PROJECT_ROOT>/.*/__tests__/.*
|
||||
|
||||
# Ignore Docs
|
||||
.*/docs/.*
|
||||
<PROJECT_ROOT>/.*/docs/.*
|
||||
|
||||
[include]
|
||||
|
||||
@@ -21,17 +21,17 @@ module.system=haste
|
||||
esproposal.class_static_fields=enable
|
||||
esproposal.class_instance_fields=enable
|
||||
|
||||
experimental.strict_type_args=true
|
||||
|
||||
munge_underscores=false
|
||||
|
||||
suppress_type=$FlowIssue
|
||||
suppress_type=$FlowFixMe
|
||||
suppress_type=$FixMe
|
||||
suppress_type=$FlowExpectedError
|
||||
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*\\)?)\\)
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(2[0-4]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*\\)?)\\)? #[0-9]+
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(3[0-1]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*www[a-z,_]*\\)?)\\)
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(3[0-1]\\|[1-2][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*www[a-z,_]*\\)?)\\)?:? #[0-9]+
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
|
||||
|
||||
[version]
|
||||
^0.27.0
|
||||
^0.31.0
|
||||
@@ -18,6 +18,7 @@ docs/js/*
|
||||
docs/downloads/*.zip
|
||||
docs/vendor/bundle
|
||||
examples/shared/*.js
|
||||
examples/**/bundle.js
|
||||
test/the-files-to-test.generated.js
|
||||
*.log*
|
||||
chrome-user-data
|
||||
|
||||
+30
-10
@@ -28,8 +28,8 @@ script:
|
||||
|
||||
GH_PAGES_DIR="$TRAVIS_BUILD_DIR"/../react-gh-pages
|
||||
echo "machine github.com login reactjs-bot password $GITHUB_TOKEN" >~/.netrc
|
||||
git config --global user.name "Travis CI"
|
||||
git config --global user.email "travis@reactjs.org"
|
||||
git config --global user.name "$GITHUB_USER_NAME"
|
||||
git config --global user.email "$GITHUB_USER_EMAIL"
|
||||
|
||||
git clone --branch gh-pages --depth=50 \
|
||||
https://reactjs-bot@github.com/facebook/react.git \
|
||||
@@ -71,20 +71,40 @@ script:
|
||||
fi
|
||||
elif [ "$TEST_TYPE" = test ]; then
|
||||
set -e
|
||||
# Disabling coverage because it's broken:
|
||||
# https://travis-ci.org/facebook/react/jobs/128163922
|
||||
if false; then
|
||||
./node_modules/.bin/grunt jest:coverage
|
||||
cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
|
||||
else
|
||||
./node_modules/.bin/grunt jest:normal
|
||||
fi
|
||||
./node_modules/.bin/grunt jest:coverage
|
||||
cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
|
||||
|
||||
echo 'Testing in server-render (HTML generation) mode...'
|
||||
printf '\nmodule.exports.useCreateElement = false;\n' \
|
||||
>> src/renderers/dom/shared/ReactDOMFeatureFlags.js
|
||||
./node_modules/.bin/grunt jest:normal
|
||||
git checkout -- src/renderers/dom/shared/ReactDOMFeatureFlags.js
|
||||
|
||||
echo 'Testing in fiber mode...'
|
||||
printf '\nmodule.exports.useFiber = true;\n' \
|
||||
>> src/renderers/dom/shared/ReactDOMFeatureFlags.js
|
||||
FIBER_TESTS=`\
|
||||
NODE_ENV=test node node_modules/jest/bin/jest --json | \
|
||||
node -e "\
|
||||
var data = JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8')); \
|
||||
console.log(data.numPassedTests + '/' + data.numTotalTests)\
|
||||
"\
|
||||
`
|
||||
git checkout -- src/renderers/dom/shared/ReactDOMFeatureFlags.js
|
||||
node scripts/facts-tracker/index.js \
|
||||
"fiber-tests" "$FIBER_TESTS"
|
||||
|
||||
./node_modules/.bin/gulp react:extract-errors
|
||||
elif [ "$TEST_TYPE" = flow ]; then
|
||||
set -e
|
||||
./node_modules/.bin/grunt flow
|
||||
|
||||
ALL_FILES=`find src -name '*.js' | grep -v umd/ | grep -v __tests__ | grep -v __mocks__`
|
||||
COUNT_ALL_FILES=`echo "$ALL_FILES" | wc -l`
|
||||
COUNT_WITH_FLOW=`grep '@flow' $ALL_FILES | perl -pe 's/:.+//' | wc -l`
|
||||
node scripts/facts-tracker/index.js \
|
||||
"flow-files" "$COUNT_WITH_FLOW/$COUNT_ALL_FILES"
|
||||
|
||||
else
|
||||
./node_modules/.bin/grunt $TEST_TYPE
|
||||
fi
|
||||
|
||||
+36
-2
@@ -117,12 +117,41 @@ module.exports = function(grunt) {
|
||||
'build-modules',
|
||||
'browserify:addonsMin',
|
||||
]);
|
||||
grunt.registerTask('build:dom', [
|
||||
'build-modules',
|
||||
'version-check',
|
||||
'browserify:dom',
|
||||
]);
|
||||
grunt.registerTask('build:dom-min', [
|
||||
'build-modules',
|
||||
'version-check',
|
||||
'browserify:domMin',
|
||||
]);
|
||||
grunt.registerTask('build:dom-server', [
|
||||
'build-modules',
|
||||
'version-check',
|
||||
'browserify:domServer',
|
||||
]);
|
||||
grunt.registerTask('build:dom-server-min', [
|
||||
'build-modules',
|
||||
'version-check',
|
||||
'browserify:domServerMin',
|
||||
]);
|
||||
grunt.registerTask('build:dom-fiber', [
|
||||
'build-modules',
|
||||
'version-check',
|
||||
'browserify:domFiber',
|
||||
]);
|
||||
grunt.registerTask('build:dom-fiber-min', [
|
||||
'build-modules',
|
||||
'version-check',
|
||||
'browserify:domFiberMin',
|
||||
]);
|
||||
grunt.registerTask('build:npm-react', [
|
||||
'version-check',
|
||||
'build-modules',
|
||||
'npm-react:release',
|
||||
]);
|
||||
grunt.registerTask('build:react-dom', require('./grunt/tasks/react-dom'));
|
||||
|
||||
var jestTasks = require('./grunt/tasks/jest');
|
||||
grunt.registerTask('jest:normal', jestTasks.normal);
|
||||
@@ -141,7 +170,12 @@ module.exports = function(grunt) {
|
||||
'browserify:addons',
|
||||
'browserify:min',
|
||||
'browserify:addonsMin',
|
||||
'build:react-dom',
|
||||
'browserify:dom',
|
||||
'browserify:domMin',
|
||||
'browserify:domServer',
|
||||
'browserify:domServerMin',
|
||||
'browserify:domFiber',
|
||||
'browserify:domFiberMin',
|
||||
'npm-react:release',
|
||||
'npm-react:pack',
|
||||
'npm-react-dom:release',
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
---
|
||||
title: Invalid ARIA Prop Warning
|
||||
layout: single
|
||||
permalink: warnings/invalid-aria-prop.html
|
||||
---
|
||||
|
||||
The invalid-aria-prop warning will fire if you attempt to render a DOM element with an aria-* prop that does not exist in the Web Accessibility Initiative (WAI) Accessible Rich Internet Application (ARIA) [specification](https://www.w3.org/TR/wai-aria-1.1/#states_and_properties).
|
||||
|
||||
1. If you feel that you are using a valid prop, check the spelling carefully. `aria-labelledby` and `aria-activedescendant` are often misspelled.
|
||||
|
||||
2. React does not yet recognize the attribute you specified. This will likely be fixed in a future version of React. However, React currently strips all unknown attributes, so specifying them in your React app will not cause them to be rendered
|
||||
@@ -18,7 +18,7 @@
|
||||
</p>
|
||||
</div>
|
||||
<script src="../../build/react.js"></script>
|
||||
<script src="../../build/react-dom.js"></script>
|
||||
<script src="../../build/react-dom-fiber.js"></script>
|
||||
<script>
|
||||
function ExampleApplication(props) {
|
||||
var elapsed = Math.round(props.elapsed / 100);
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
var start = new Date().getTime();
|
||||
setInterval(function() {
|
||||
ReactDOM.render(
|
||||
ReactDOMFiber.render(
|
||||
ExampleApplicationFactory({elapsed: new Date().getTime() - start}),
|
||||
document.getElementById('container')
|
||||
);
|
||||
|
||||
Vendored
+3
-1
@@ -40,4 +40,6 @@ declare module 'UIManager' {
|
||||
declare function setChildren() : void;
|
||||
declare function updateView() : void;
|
||||
}
|
||||
declare module 'View' { }
|
||||
declare module 'View' {
|
||||
declare var exports : typeof ReactComponent;
|
||||
}
|
||||
+170
-5
@@ -7,11 +7,26 @@ var grunt = require('grunt');
|
||||
var UglifyJS = require('uglify-js');
|
||||
var uglifyify = require('uglifyify');
|
||||
var derequire = require('derequire');
|
||||
var aliasify = require('aliasify');
|
||||
var collapser = require('bundle-collapser/plugin');
|
||||
|
||||
var envifyDev = envify({NODE_ENV: process.env.NODE_ENV || 'development'});
|
||||
var envifyProd = envify({NODE_ENV: process.env.NODE_ENV || 'production'});
|
||||
|
||||
var shimSharedModules = aliasify.configure({
|
||||
'aliases': {
|
||||
'react/lib/React': 'react/lib/ReactUMDShim',
|
||||
'react/lib/ReactCurrentOwner': 'react/lib/ReactCurrentOwnerUMDShim',
|
||||
'react/lib/ReactComponentTreeHook': 'react/lib/ReactComponentTreeHookUMDShim',
|
||||
},
|
||||
});
|
||||
|
||||
var shimDOMModules = aliasify.configure({
|
||||
'aliases': {
|
||||
'./ReactAddonsDOMDependencies': {relative: './ReactAddonsDOMDependenciesUMDShim'},
|
||||
},
|
||||
});
|
||||
|
||||
var SIMPLE_TEMPLATE =
|
||||
grunt.file.read('./grunt/data/header-template-short.txt');
|
||||
|
||||
@@ -47,10 +62,56 @@ function simpleBannerify(src) {
|
||||
);
|
||||
}
|
||||
|
||||
// What is happening here???
|
||||
// I'm glad you asked. It became really to make our bundle splitting work.
|
||||
// Everything is fine in node and when bundling with those packages, but when
|
||||
// using our pre-packaged files, the splitting didn't work. Specifically due to
|
||||
// the UMD wrappers defining their own require and creating their own encapsulated
|
||||
// "registry" scope, we couldn't require across the boundaries. Webpack tries to
|
||||
// be smart and looks for top-level requires (even when aliasing to a bundle),
|
||||
// but since we didn't have those, we couldn't require 'react' from 'react-dom'.
|
||||
// But we are already shimming in some modules that look for a global React
|
||||
// variable. So we write a wrapper around the UMD bundle that browserify creates,
|
||||
// and define a React variable that will require across Webpack-boundaries or fall
|
||||
// back to the global, just like it would previously.
|
||||
function wrapperify(src) {
|
||||
return `
|
||||
;(function(f) {
|
||||
// CommonJS
|
||||
if (typeof exports === "object" && typeof module !== "undefined") {
|
||||
f(require('react'));
|
||||
|
||||
// RequireJS
|
||||
} else if (typeof define === "function" && define.amd) {
|
||||
require(['react'], f);
|
||||
|
||||
// <script>
|
||||
} else {
|
||||
var g;
|
||||
if (typeof window !== "undefined") {
|
||||
g = window;
|
||||
} else if (typeof global !== "undefined") {
|
||||
g = global;
|
||||
} else if (typeof self !== "undefined") {
|
||||
g = self;
|
||||
} else {
|
||||
// works providing we're not in "use strict";
|
||||
// needed for Java 8 Nashorn
|
||||
// see https://github.com/facebook/react/issues/3037
|
||||
g = this;
|
||||
}
|
||||
f(g.React)
|
||||
}
|
||||
})(function(React) {
|
||||
${src}
|
||||
});
|
||||
`;
|
||||
}
|
||||
|
||||
// Our basic config which we'll add to to make our other builds
|
||||
var basic = {
|
||||
entries: [
|
||||
'./build/modules/ReactUMDEntry.js',
|
||||
'./build/node_modules/react/lib/ReactUMDEntry.js',
|
||||
],
|
||||
outfile: './build/react.js',
|
||||
debug: false,
|
||||
@@ -63,7 +124,7 @@ var basic = {
|
||||
|
||||
var min = {
|
||||
entries: [
|
||||
'./build/modules/ReactUMDEntry.js',
|
||||
'./build/node_modules/react/lib/ReactUMDEntry.js',
|
||||
],
|
||||
outfile: './build/react.min.js',
|
||||
debug: false,
|
||||
@@ -81,12 +142,13 @@ var min = {
|
||||
|
||||
var addons = {
|
||||
entries: [
|
||||
'./build/modules/ReactWithAddonsUMDEntry.js',
|
||||
'./build/node_modules/react/lib/ReactWithAddonsUMDEntry.js',
|
||||
],
|
||||
outfile: './build/react-with-addons.js',
|
||||
debug: false,
|
||||
standalone: 'React',
|
||||
packageName: 'React (with addons)',
|
||||
transforms: [shimDOMModules],
|
||||
globalTransforms: [envifyDev],
|
||||
plugins: [collapser],
|
||||
after: [derequire, simpleBannerify],
|
||||
@@ -94,13 +156,13 @@ var addons = {
|
||||
|
||||
var addonsMin = {
|
||||
entries: [
|
||||
'./build/modules/ReactWithAddonsUMDEntry.js',
|
||||
'./build/node_modules/react/lib/ReactWithAddonsUMDEntry.js',
|
||||
],
|
||||
outfile: './build/react-with-addons.min.js',
|
||||
debug: false,
|
||||
standalone: 'React',
|
||||
packageName: 'React (with addons)',
|
||||
transforms: [envifyProd, uglifyify],
|
||||
transforms: [shimDOMModules, envifyProd, uglifyify],
|
||||
globalTransforms: [envifyProd],
|
||||
plugins: [collapser],
|
||||
// No need to derequire because the minifier will mangle
|
||||
@@ -109,9 +171,112 @@ var addonsMin = {
|
||||
after: [minify, bannerify],
|
||||
};
|
||||
|
||||
// The DOM Builds
|
||||
var dom = {
|
||||
entries: [
|
||||
'./build/node_modules/react-dom/lib/ReactDOMUMDEntry.js',
|
||||
],
|
||||
outfile: './build/react-dom.js',
|
||||
debug: false,
|
||||
standalone: 'ReactDOM',
|
||||
// Apply as global transform so that we also envify fbjs and any other deps
|
||||
transforms: [shimSharedModules],
|
||||
globalTransforms: [envifyDev],
|
||||
plugins: [collapser],
|
||||
after: [derequire, wrapperify, simpleBannerify],
|
||||
};
|
||||
|
||||
var domMin = {
|
||||
entries: [
|
||||
'./build/node_modules/react-dom/lib/ReactDOMUMDEntry.js',
|
||||
],
|
||||
outfile: './build/react-dom.min.js',
|
||||
debug: false,
|
||||
standalone: 'ReactDOM',
|
||||
// Envify twice. The first ensures that when we uglifyify, we have the right
|
||||
// conditions to exclude requires. The global transform runs on deps.
|
||||
transforms: [shimSharedModules, envifyProd, uglifyify],
|
||||
globalTransforms: [envifyProd],
|
||||
plugins: [collapser],
|
||||
// No need to derequire because the minifier will mangle
|
||||
// the "require" calls.
|
||||
|
||||
after: [wrapperify, minify, bannerify],
|
||||
};
|
||||
|
||||
var domServer = {
|
||||
entries: [
|
||||
'./build/node_modules/react-dom/lib/ReactDOMServerUMDEntry.js',
|
||||
],
|
||||
outfile: './build/react-dom-server.js',
|
||||
debug: false,
|
||||
standalone: 'ReactDOMServer',
|
||||
// Apply as global transform so that we also envify fbjs and any other deps
|
||||
transforms: [shimSharedModules],
|
||||
globalTransforms: [envifyDev],
|
||||
plugins: [collapser],
|
||||
after: [derequire, wrapperify, simpleBannerify],
|
||||
};
|
||||
|
||||
var domServerMin = {
|
||||
entries: [
|
||||
'./build/node_modules/react-dom/lib/ReactDOMServerUMDEntry.js',
|
||||
],
|
||||
outfile: './build/react-dom-server.min.js',
|
||||
debug: false,
|
||||
standalone: 'ReactDOMServer',
|
||||
// Envify twice. The first ensures that when we uglifyify, we have the right
|
||||
// conditions to exclude requires. The global transform runs on deps.
|
||||
transforms: [shimSharedModules, envifyProd, uglifyify],
|
||||
globalTransforms: [envifyProd],
|
||||
plugins: [collapser],
|
||||
// No need to derequire because the minifier will mangle
|
||||
// the "require" calls.
|
||||
|
||||
after: [wrapperify, minify, bannerify],
|
||||
};
|
||||
|
||||
var domFiber = {
|
||||
entries: [
|
||||
'./build/node_modules/react-dom/lib/ReactDOMFiber.js',
|
||||
],
|
||||
outfile: './build/react-dom-fiber.js',
|
||||
debug: false,
|
||||
standalone: 'ReactDOMFiber',
|
||||
// Apply as global transform so that we also envify fbjs and any other deps
|
||||
transforms: [shimSharedModules],
|
||||
globalTransforms: [envifyDev],
|
||||
plugins: [collapser],
|
||||
after: [derequire, wrapperify, simpleBannerify],
|
||||
};
|
||||
|
||||
var domFiberMin = {
|
||||
entries: [
|
||||
'./build/node_modules/react-dom/lib/ReactDOMFiber.js',
|
||||
],
|
||||
outfile: './build/react-dom-fiber.min.js',
|
||||
debug: false,
|
||||
standalone: 'ReactDOMFiber',
|
||||
// Envify twice. The first ensures that when we uglifyify, we have the right
|
||||
// conditions to exclude requires. The global transform runs on deps.
|
||||
transforms: [shimSharedModules, envifyProd, uglifyify],
|
||||
globalTransforms: [envifyProd],
|
||||
plugins: [collapser],
|
||||
// No need to derequire because the minifier will mangle
|
||||
// the "require" calls.
|
||||
|
||||
after: [wrapperify, minify, bannerify],
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
basic: basic,
|
||||
min: min,
|
||||
addons: addons,
|
||||
addonsMin: addonsMin,
|
||||
dom: dom,
|
||||
domMin: domMin,
|
||||
domServer: domServer,
|
||||
domServerMin: domServerMin,
|
||||
domFiber: domFiber,
|
||||
domFiberMin: domFiberMin,
|
||||
};
|
||||
+6
-81
@@ -1,84 +1,16 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var fs = require('fs');
|
||||
var glob = require('glob');
|
||||
var grunt = require('grunt');
|
||||
var path = require('path');
|
||||
|
||||
var rootPath = path.resolve('.');
|
||||
var buildPath = path.join(rootPath, 'build');
|
||||
var tempConfigPath = path.join(buildPath, 'jest-config.json');
|
||||
|
||||
var config = require(path.join(rootPath, 'package.json')).jest;
|
||||
|
||||
var collectCoverageOnlyFrom = {
|
||||
'src/**/*.js': {
|
||||
ignore: [
|
||||
'src/**/__tests__/*.js',
|
||||
'src/shared/vendor/third_party/*.js',
|
||||
'src/test/*.js',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
function getCollectCoverageOnlyFrom(callback) {
|
||||
var patterns = Object.keys(collectCoverageOnlyFrom);
|
||||
var result = {};
|
||||
|
||||
async.each(patterns, function(pattern) {
|
||||
var options = Object.assign({ nodir: true }, collectCoverageOnlyFrom[pattern]);
|
||||
glob(pattern, options, function(err, files) {
|
||||
(files || []).reduce(function(object, key) {
|
||||
object[key] = true;
|
||||
return object;
|
||||
}, result);
|
||||
|
||||
callback(err);
|
||||
});
|
||||
}, function(err) {
|
||||
callback(err, result);
|
||||
});
|
||||
}
|
||||
|
||||
function getJestConfig(callback) {
|
||||
var rootDir = path.resolve(buildPath, path.resolve(config.rootDir));
|
||||
getCollectCoverageOnlyFrom(function(err, data) {
|
||||
callback(err, Object.assign({}, config, {
|
||||
rootDir: rootDir,
|
||||
name: 'react',
|
||||
collectCoverage: true,
|
||||
collectCoverageOnlyFrom: data,
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
function onError(err) {
|
||||
grunt.log.error('jest failed');
|
||||
grunt.log.error(err);
|
||||
}
|
||||
|
||||
function writeTempConfig(callback) {
|
||||
getJestConfig(function(err, data) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
grunt.file.mkdir(buildPath);
|
||||
fs.writeFile(tempConfigPath, JSON.stringify(data, null, ' '), 'utf8', callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function run(done, configPath) {
|
||||
function run(done, coverage) {
|
||||
grunt.log.writeln('running jest');
|
||||
|
||||
var args = [
|
||||
path.join('node_modules', 'jest', 'bin', 'jest'),
|
||||
'--runInBand',
|
||||
'--no-watchman',
|
||||
];
|
||||
if (configPath) {
|
||||
args.push('--config', configPath);
|
||||
if (coverage) {
|
||||
args.push('--coverage');
|
||||
}
|
||||
grunt.util.spawn({
|
||||
cmd: 'node',
|
||||
@@ -91,7 +23,8 @@ function run(done, configPath) {
|
||||
},
|
||||
}, function(spawnErr, result, code) {
|
||||
if (spawnErr) {
|
||||
onError(spawnErr);
|
||||
grunt.log.error('jest failed');
|
||||
grunt.log.error(spawnErr);
|
||||
} else {
|
||||
grunt.log.ok('jest passed');
|
||||
}
|
||||
@@ -108,15 +41,7 @@ function runJestNormally() {
|
||||
|
||||
function runJestWithCoverage() {
|
||||
var done = this.async();
|
||||
|
||||
writeTempConfig(function(writeErr) {
|
||||
if (writeErr) {
|
||||
onError(writeErr);
|
||||
return;
|
||||
}
|
||||
|
||||
run(done, tempConfigPath);
|
||||
});
|
||||
run(done, /* coverage */ true);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -6,47 +6,56 @@ var path = require('path');
|
||||
|
||||
var addons = {
|
||||
CSSTransitionGroup: {
|
||||
peerDependency: 'react',
|
||||
module: 'ReactCSSTransitionGroup',
|
||||
name: 'css-transition-group',
|
||||
docs: 'animation',
|
||||
},
|
||||
LinkedStateMixin: {
|
||||
peerDependency: 'react',
|
||||
module: 'LinkedStateMixin',
|
||||
name: 'linked-state-mixin',
|
||||
docs: 'two-way-binding-helpers',
|
||||
},
|
||||
Perf: {
|
||||
peerDependency: 'react-dom',
|
||||
module: 'ReactPerf',
|
||||
name: 'perf',
|
||||
docs: 'perf',
|
||||
},
|
||||
PureRenderMixin: {
|
||||
peerDependency: 'react',
|
||||
module: 'ReactComponentWithPureRenderMixin',
|
||||
name: 'pure-render-mixin',
|
||||
docs: 'pure-render-mixin',
|
||||
},
|
||||
TestUtils: {
|
||||
peerDependency: 'react-dom',
|
||||
module: 'ReactTestUtils',
|
||||
name: 'test-utils',
|
||||
docs: 'test-utils',
|
||||
},
|
||||
TransitionGroup: {
|
||||
peerDependency: 'react',
|
||||
module: 'ReactTransitionGroup',
|
||||
name: 'transition-group',
|
||||
docs: 'animation',
|
||||
},
|
||||
createFragment: {
|
||||
peerDependency: 'react',
|
||||
module: 'ReactFragment',
|
||||
method: 'create',
|
||||
name: 'create-fragment',
|
||||
docs: 'create-fragment',
|
||||
},
|
||||
shallowCompare: {
|
||||
peerDependency: 'react',
|
||||
module: 'shallowCompare',
|
||||
name: 'shallow-compare',
|
||||
docs: 'shallow-compare',
|
||||
},
|
||||
updates: {
|
||||
peerDependency: 'react',
|
||||
module: 'update',
|
||||
name: 'update',
|
||||
docs: 'update',
|
||||
@@ -55,9 +64,11 @@ var addons = {
|
||||
|
||||
function generateSource(info) {
|
||||
var pieces = [
|
||||
"module.exports = require('react/lib/",
|
||||
'module.exports = require(\'',
|
||||
info.peerDependency,
|
||||
'/lib/',
|
||||
info.module,
|
||||
"')",
|
||||
'\')',
|
||||
];
|
||||
if (info.method) {
|
||||
pieces.push('.', info.method);
|
||||
@@ -79,6 +90,12 @@ function buildReleases() {
|
||||
var pkgData = Object.assign({}, pkgTemplate);
|
||||
pkgData.name = pkgName;
|
||||
|
||||
var version = pkgTemplate.peerDependencies.react;
|
||||
if (info.peerDependency !== 'react') {
|
||||
pkgData.peerDependencies = {};
|
||||
pkgData.peerDependencies[info.peerDependency] = version;
|
||||
}
|
||||
|
||||
grunt.file.mkdir(destDir);
|
||||
var link = info.docs ? info.docs : 'addons';
|
||||
link = `https://facebook.github.io/react/docs/${link}.html`;
|
||||
|
||||
@@ -5,6 +5,8 @@ var grunt = require('grunt');
|
||||
|
||||
var src = 'packages/react-dom/';
|
||||
var dest = 'build/packages/react-dom/';
|
||||
var modSrc = 'build/node_modules/react-dom/lib';
|
||||
var lib = dest + 'lib/';
|
||||
var dist = dest + 'dist/';
|
||||
var distFiles = [
|
||||
'react-dom.js',
|
||||
@@ -21,6 +23,7 @@ function buildRelease() {
|
||||
// Copy to build/packages/react-dom
|
||||
var mappings = [].concat(
|
||||
grunt.file.expandMapping('**/*', dest, {cwd: src}),
|
||||
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
|
||||
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
|
||||
);
|
||||
mappings.forEach(function(mapping) {
|
||||
|
||||
@@ -5,6 +5,8 @@ var grunt = require('grunt');
|
||||
|
||||
var src = 'packages/react-native-renderer/';
|
||||
var dest = 'build/packages/react-native-renderer/';
|
||||
var modSrc = 'build/node_modules/react-native/lib';
|
||||
var lib = dest + 'lib/';
|
||||
|
||||
function buildRelease() {
|
||||
if (grunt.file.exists(dest)) {
|
||||
@@ -14,6 +16,7 @@ function buildRelease() {
|
||||
// Copy to build/packages/react-native-renderer
|
||||
var mappings = [].concat(
|
||||
grunt.file.expandMapping('**/*', dest, {cwd: src}),
|
||||
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
|
||||
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
|
||||
);
|
||||
mappings.forEach(function(mapping) {
|
||||
@@ -32,9 +35,12 @@ function packRelease() {
|
||||
var spawnCmd = {
|
||||
cmd: 'npm',
|
||||
args: ['pack', 'packages/react-native-renderer'],
|
||||
opts: {
|
||||
cwd: 'build/',
|
||||
},
|
||||
};
|
||||
grunt.util.spawn(spawnCmd, function() {
|
||||
var buildSrc = 'react-native-renderer-' + grunt.config.data.pkg.version + '.tgz';
|
||||
var buildSrc = 'build/react-native-renderer-' + grunt.config.data.pkg.version + '.tgz';
|
||||
var buildDest = 'build/packages/react-native-renderer.tgz';
|
||||
fs.rename(buildSrc, buildDest, done);
|
||||
});
|
||||
|
||||
@@ -5,6 +5,8 @@ var grunt = require('grunt');
|
||||
|
||||
var src = 'packages/react-test-renderer/';
|
||||
var dest = 'build/packages/react-test-renderer/';
|
||||
var modSrc = 'build/node_modules/react-test-renderer/lib';
|
||||
var lib = dest + 'lib/';
|
||||
|
||||
function buildRelease() {
|
||||
if (grunt.file.exists(dest)) {
|
||||
@@ -14,6 +16,7 @@ function buildRelease() {
|
||||
// Copy to build/packages/react-native-renderer
|
||||
var mappings = [].concat(
|
||||
grunt.file.expandMapping('**/*', dest, {cwd: src}),
|
||||
grunt.file.expandMapping('**/*', lib, {cwd: modSrc}),
|
||||
grunt.file.expandMapping('{LICENSE,PATENTS}', dest)
|
||||
);
|
||||
mappings.forEach(function(mapping) {
|
||||
@@ -32,9 +35,12 @@ function packRelease() {
|
||||
var spawnCmd = {
|
||||
cmd: 'npm',
|
||||
args: ['pack', 'packages/react-test-renderer'],
|
||||
opts: {
|
||||
cwd: 'build/',
|
||||
},
|
||||
};
|
||||
grunt.util.spawn(spawnCmd, function() {
|
||||
var buildSrc = 'react-test-renderer-' + grunt.config.data.pkg.version + '.tgz';
|
||||
var buildSrc = 'build/react-test-renderer-' + grunt.config.data.pkg.version + '.tgz';
|
||||
var buildDest = 'build/packages/react-test-renderer.tgz';
|
||||
fs.rename(buildSrc, buildDest, done);
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ var grunt = require('grunt');
|
||||
|
||||
var src = 'packages/react/';
|
||||
var dest = 'build/packages/react/';
|
||||
var modSrc = 'build/modules/';
|
||||
var modSrc = 'build/node_modules/react/lib';
|
||||
var lib = dest + 'lib/';
|
||||
var dist = dest + 'dist/';
|
||||
var distFiles = [
|
||||
|
||||
Vendored
-30
@@ -1,30 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var grunt = require('grunt');
|
||||
var UglifyJS = require('uglify-js');
|
||||
|
||||
var LICENSE_TEMPLATE =
|
||||
grunt.file.read('./grunt/data/header-template-extended.txt');
|
||||
|
||||
function build(name, filename) {
|
||||
var srcFile = `vendor/${filename}.js`;
|
||||
var destFile = `build/${filename}.js`;
|
||||
var destFileMin = `build/${filename}.min.js`;
|
||||
var templateData = {
|
||||
package: name,
|
||||
version: grunt.config.data.pkg.version,
|
||||
};
|
||||
var header = grunt.template.process(
|
||||
LICENSE_TEMPLATE,
|
||||
{data: templateData}
|
||||
);
|
||||
var src = grunt.file.read(srcFile);
|
||||
var srcMin = UglifyJS.minify(src, {fromString: true}).code;
|
||||
grunt.file.write(destFile, header + src);
|
||||
grunt.file.write(destFileMin, header + srcMin);
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
build('ReactDOM', 'react-dom');
|
||||
build('ReactDOMServer', 'react-dom-server');
|
||||
};
|
||||
+162
-21
@@ -13,8 +13,10 @@ var gulp = require('gulp');
|
||||
var babel = require('gulp-babel');
|
||||
var flatten = require('gulp-flatten');
|
||||
var del = require('del');
|
||||
var merge = require('merge-stream');
|
||||
|
||||
var babelPluginModules = require('fbjs-scripts/babel-6/rewrite-modules');
|
||||
var stripProvidesModule = require('fbjs-scripts/gulp/strip-provides-module');
|
||||
var extractErrors = require('./scripts/error-codes/gulp-extract-errors');
|
||||
var devExpressionWithCodes = require('./scripts/error-codes/dev-expression-with-codes');
|
||||
|
||||
@@ -28,22 +30,104 @@ function getTask(name) {
|
||||
var paths = {
|
||||
react: {
|
||||
src: [
|
||||
'src/**/*.js',
|
||||
'src/umd/ReactUMDEntry.js',
|
||||
'src/umd/ReactWithAddonsUMDEntry.js',
|
||||
'src/umd/shims/**/*.js',
|
||||
|
||||
'src/isomorphic/**/*.js',
|
||||
'src/addons/**/*.js',
|
||||
|
||||
'src/ReactVersion.js',
|
||||
'src/shared/**/*.js',
|
||||
'!src/shared/vendor/**/*.js',
|
||||
'!src/**/__benchmarks__/**/*.js',
|
||||
'!src/**/__tests__/**/*.js',
|
||||
'!src/**/__mocks__/**/*.js',
|
||||
'!src/renderers/art/**/*.js',
|
||||
'!src/renderers/shared/fiber/**/*.js',
|
||||
'!src/shared/vendor/**/*.js',
|
||||
],
|
||||
lib: 'build/modules',
|
||||
lib: 'build/node_modules/react/lib',
|
||||
},
|
||||
reactDOM: {
|
||||
src: [
|
||||
'src/umd/ReactDOMUMDEntry.js',
|
||||
'src/umd/ReactDOMServerUMDEntry.js',
|
||||
|
||||
'src/renderers/dom/**/*.js',
|
||||
'src/renderers/shared/**/*.js',
|
||||
'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.
|
||||
|
||||
'src/ReactVersion.js',
|
||||
'src/shared/**/*.js',
|
||||
'!src/shared/vendor/**/*.js',
|
||||
'!src/**/__benchmarks__/**/*.js',
|
||||
'!src/**/__tests__/**/*.js',
|
||||
'!src/**/__mocks__/**/*.js',
|
||||
],
|
||||
lib: 'build/node_modules/react-dom/lib',
|
||||
},
|
||||
reactNative: {
|
||||
src: [
|
||||
'src/renderers/native/**/*.js',
|
||||
'src/renderers/shared/**/*.js',
|
||||
|
||||
'src/ReactVersion.js',
|
||||
'src/shared/**/*.js',
|
||||
'!src/shared/vendor/**/*.js',
|
||||
'!src/**/__benchmarks__/**/*.js',
|
||||
'!src/**/__tests__/**/*.js',
|
||||
'!src/**/__mocks__/**/*.js',
|
||||
],
|
||||
lib: 'build/node_modules/react-native/lib',
|
||||
},
|
||||
reactTestRenderer: {
|
||||
src: [
|
||||
'src/renderers/testing/**/*.js',
|
||||
'src/renderers/shared/**/*.js',
|
||||
|
||||
'src/ReactVersion.js',
|
||||
'src/shared/**/*.js',
|
||||
'!src/shared/vendor/**/*.js',
|
||||
'!src/**/__benchmarks__/**/*.js',
|
||||
'!src/**/__tests__/**/*.js',
|
||||
'!src/**/__mocks__/**/*.js',
|
||||
],
|
||||
lib: 'build/node_modules/react-test-renderer/lib',
|
||||
},
|
||||
};
|
||||
|
||||
var moduleMap = Object.assign(
|
||||
var moduleMapBase = Object.assign(
|
||||
{'object-assign': 'object-assign'},
|
||||
require('fbjs/module-map'),
|
||||
require('fbjs/module-map')
|
||||
);
|
||||
|
||||
var moduleMapReact = Object.assign(
|
||||
{
|
||||
// Addons needs to reach into DOM internals
|
||||
ReactDOM: 'react-dom/lib/ReactDOM',
|
||||
ReactInstanceMap: 'react-dom/lib/ReactInstanceMap',
|
||||
ReactTestUtils: 'react-dom/lib/ReactTestUtils',
|
||||
ReactPerf: 'react-dom/lib/ReactPerf',
|
||||
getVendorPrefixedEventName: 'react-dom/lib/getVendorPrefixedEventName',
|
||||
},
|
||||
moduleMapBase
|
||||
);
|
||||
|
||||
var rendererSharedState = {
|
||||
// Alias
|
||||
React: 'react/lib/React',
|
||||
// Shared state
|
||||
ReactCurrentOwner: 'react/lib/ReactCurrentOwner',
|
||||
ReactComponentTreeHook: 'react/lib/ReactComponentTreeHook',
|
||||
};
|
||||
|
||||
var moduleMapReactDOM = Object.assign(
|
||||
{},
|
||||
rendererSharedState,
|
||||
moduleMapBase
|
||||
);
|
||||
|
||||
var moduleMapReactNative = Object.assign(
|
||||
{
|
||||
// React Native Hooks
|
||||
deepDiffer: 'react-native/lib/deepDiffer',
|
||||
deepFreezeAndThrowOnMutationInDev: 'react-native/lib/deepFreezeAndThrowOnMutationInDev',
|
||||
flattenStyle: 'react-native/lib/flattenStyle',
|
||||
@@ -53,17 +137,46 @@ var moduleMap = Object.assign(
|
||||
UIManager: 'react-native/lib/UIManager',
|
||||
UIManagerStatTracker: 'react-native/lib/UIManagerStatTracker',
|
||||
View: 'react-native/lib/View',
|
||||
}
|
||||
},
|
||||
rendererSharedState,
|
||||
moduleMapBase
|
||||
);
|
||||
|
||||
var moduleMapReactTestRenderer = Object.assign(
|
||||
{},
|
||||
rendererSharedState,
|
||||
moduleMapBase
|
||||
);
|
||||
|
||||
var errorCodeOpts = {
|
||||
errorMapFilePath: 'scripts/error-codes/codes.json',
|
||||
};
|
||||
|
||||
var babelOpts = {
|
||||
var babelOptsReact = {
|
||||
plugins: [
|
||||
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
|
||||
[babelPluginModules, {map: moduleMap}],
|
||||
[babelPluginModules, {map: moduleMapReact}],
|
||||
],
|
||||
};
|
||||
|
||||
var babelOptsReactDOM = {
|
||||
plugins: [
|
||||
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
|
||||
[babelPluginModules, {map: moduleMapReactDOM}],
|
||||
],
|
||||
};
|
||||
|
||||
var babelOptsReactNative = {
|
||||
plugins: [
|
||||
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
|
||||
[babelPluginModules, {map: moduleMapReactNative}],
|
||||
],
|
||||
};
|
||||
|
||||
var babelOptsReactTestRenderer = {
|
||||
plugins: [
|
||||
devExpressionWithCodes, // this pass has to run before `rewrite-modules`
|
||||
[babelPluginModules, {map: moduleMapReactTestRenderer}],
|
||||
],
|
||||
};
|
||||
|
||||
@@ -76,24 +189,52 @@ gulp.task('flow', getTask('flow'));
|
||||
gulp.task('version-check', getTask('version-check'));
|
||||
|
||||
gulp.task('react:clean', function() {
|
||||
return del([paths.react.lib]);
|
||||
return del([
|
||||
paths.react.lib,
|
||||
paths.reactDOM.lib,
|
||||
paths.reactNative.lib,
|
||||
paths.reactTestRenderer.lib,
|
||||
]);
|
||||
});
|
||||
|
||||
gulp.task('react:modules', function() {
|
||||
return gulp
|
||||
.src(paths.react.src)
|
||||
.pipe(babel(babelOpts))
|
||||
.pipe(flatten())
|
||||
.pipe(gulp.dest(paths.react.lib));
|
||||
return merge(
|
||||
gulp
|
||||
.src(paths.react.src)
|
||||
.pipe(babel(babelOptsReact))
|
||||
.pipe(stripProvidesModule())
|
||||
.pipe(flatten())
|
||||
.pipe(gulp.dest(paths.react.lib)),
|
||||
|
||||
gulp
|
||||
.src(paths.reactDOM.src)
|
||||
.pipe(babel(babelOptsReactDOM))
|
||||
.pipe(stripProvidesModule())
|
||||
.pipe(flatten())
|
||||
.pipe(gulp.dest(paths.reactDOM.lib)),
|
||||
|
||||
gulp
|
||||
.src(paths.reactNative.src)
|
||||
.pipe(babel(babelOptsReactNative))
|
||||
.pipe(stripProvidesModule())
|
||||
.pipe(flatten())
|
||||
.pipe(gulp.dest(paths.reactNative.lib)),
|
||||
|
||||
gulp
|
||||
.src(paths.reactTestRenderer.src)
|
||||
.pipe(stripProvidesModule())
|
||||
.pipe(babel(babelOptsReactTestRenderer))
|
||||
.pipe(flatten())
|
||||
.pipe(gulp.dest(paths.reactTestRenderer.lib))
|
||||
);
|
||||
});
|
||||
|
||||
gulp.task('react:extract-errors', function() {
|
||||
return gulp.src([].concat(
|
||||
paths.react.src
|
||||
// TODO: enable before 15.4.0 release:
|
||||
// paths.reactDOM.src,
|
||||
// paths.reactNative.src,
|
||||
// paths.reactTestRenderer.src
|
||||
paths.react.src,
|
||||
paths.reactDOM.src,
|
||||
paths.reactNative.src,
|
||||
paths.reactTestRenderer.src
|
||||
)).pipe(extractErrors(errorCodeOpts));
|
||||
});
|
||||
|
||||
|
||||
Generated
+5496
-14840
File diff suppressed because it is too large.
Load diff
+19
-10
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "react-build",
|
||||
"private": true,
|
||||
"version": "15.3.2",
|
||||
"version": "15.4.0-rc.4",
|
||||
"devDependencies": {
|
||||
"aliasify": "^2.0.0",
|
||||
"art": "^0.10.1",
|
||||
"async": "^1.5.0",
|
||||
"babel-cli": "^6.6.5",
|
||||
@@ -44,7 +45,7 @@
|
||||
"eslint-plugin-react-internal": "file:eslint-rules",
|
||||
"fbjs": "^0.8.4",
|
||||
"fbjs-scripts": "^0.6.0",
|
||||
"flow-bin": "^0.27.0",
|
||||
"flow-bin": "^0.31.0",
|
||||
"glob": "^6.0.1",
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-cli": "^0.1.13",
|
||||
@@ -57,8 +58,9 @@
|
||||
"gulp-load-plugins": "^1.2.4",
|
||||
"gulp-util": "^3.0.7",
|
||||
"gzip-js": "~0.3.2",
|
||||
"jest": "^12.1.1",
|
||||
"jest": "^15.1.1",
|
||||
"loose-envify": "^1.1.0",
|
||||
"merge-stream": "^1.0.0",
|
||||
"object-assign": "^4.1.0",
|
||||
"platform": "^1.1.0",
|
||||
"run-sequence": "^1.1.4",
|
||||
@@ -88,14 +90,18 @@
|
||||
"/.module-cache/",
|
||||
"/react/build/"
|
||||
],
|
||||
"persistModuleRegistryBetweenSpecs": true,
|
||||
"rootDir": "",
|
||||
"scriptPreprocessor": "scripts/jest/preprocessor.js",
|
||||
"setupEnvScriptFile": "scripts/jest/environment.js",
|
||||
"setupFiles": [
|
||||
"scripts/jest/environment.js"
|
||||
],
|
||||
"setupTestFrameworkScriptFile": "scripts/jest/test-framework-setup.js",
|
||||
"testFileExtensions": [
|
||||
"coffee",
|
||||
"testRegex": "/__tests__/",
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"node",
|
||||
"coffee",
|
||||
"ts"
|
||||
],
|
||||
"testPathDirs": [
|
||||
@@ -105,8 +111,11 @@
|
||||
"<rootDir>/src",
|
||||
"node_modules/fbjs"
|
||||
],
|
||||
"unmockedModulePathPatterns": [
|
||||
""
|
||||
]
|
||||
"collectCoverageFrom": [
|
||||
"src/**/*.js",
|
||||
"!src/shared/vendor/third_party/*.js",
|
||||
"!src/test/*.js"
|
||||
],
|
||||
"timers": "fake"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-addons-template",
|
||||
"version": "15.3.2",
|
||||
"version": "15.4.0-rc.4",
|
||||
"main": "index.js",
|
||||
"repository": "facebook/react",
|
||||
"keywords": [
|
||||
@@ -10,7 +10,7 @@
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {},
|
||||
"peerDependencies": {
|
||||
"react": "^15.3.2"
|
||||
"react": "^15.4.0-rc.4"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('./lib/ReactDOMFiber');
|
||||
Vendored
+1
-1
@@ -1,3 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('react/lib/ReactDOM');
|
||||
module.exports = require('./lib/ReactDOM');
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-dom",
|
||||
"version": "15.3.2",
|
||||
"version": "15.4.0-rc.4",
|
||||
"description": "React package for working with the DOM.",
|
||||
"main": "index.js",
|
||||
"repository": "facebook/react",
|
||||
@@ -12,16 +12,26 @@
|
||||
"url": "https://github.com/facebook/react/issues"
|
||||
},
|
||||
"homepage": "https://facebook.github.io/react/",
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"fbjs": "^0.8.1",
|
||||
"loose-envify": "^1.1.0",
|
||||
"object-assign": "^4.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^15.3.2"
|
||||
"react": "^15.4.0-rc.4"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"PATENTS",
|
||||
"README.md",
|
||||
"dist/",
|
||||
"lib/",
|
||||
"index.js",
|
||||
"server.js"
|
||||
]
|
||||
],
|
||||
"browserify": {
|
||||
"transform": [
|
||||
"loose-envify"
|
||||
]
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -1,3 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('react/lib/ReactDOMServer');
|
||||
module.exports = require('./lib/ReactDOMServer');
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var LinkedValueUtils = require('react/lib/LinkedValueUtils');
|
||||
var LinkedValueUtils = require('react-dom/lib/LinkedValueUtils');
|
||||
|
||||
class LinkedInput extends React.Component {
|
||||
render() {
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = require('react/lib/ReactNative');
|
||||
module.exports = require('./lib/ReactNative');
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-renderer",
|
||||
"version": "15.3.2",
|
||||
"version": "15.4.0-rc.4",
|
||||
"description": "React package for use inside react-native.",
|
||||
"main": "index.js",
|
||||
"repository": "facebook/react",
|
||||
@@ -14,12 +14,17 @@
|
||||
},
|
||||
"homepage": "https://facebook.github.io/react-native/",
|
||||
"dependencies": {
|
||||
"react": "^15.3.2"
|
||||
"fbjs": "^0.8.1",
|
||||
"object-assign": "^4.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^15.4.0-rc.4"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"PATENTS",
|
||||
"README.md",
|
||||
"index.js"
|
||||
"index.js",
|
||||
"lib/"
|
||||
]
|
||||
}
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = require('react/lib/ReactTestRenderer');
|
||||
module.exports = require('./lib/ReactTestRenderer');
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-test-renderer",
|
||||
"version": "15.3.2",
|
||||
"version": "15.4.0-rc.4",
|
||||
"description": "React package for snapshot testing.",
|
||||
"main": "index.js",
|
||||
"repository": "facebook/react",
|
||||
@@ -15,12 +15,13 @@
|
||||
},
|
||||
"homepage": "https://facebook.github.io/react/",
|
||||
"peerDependencies": {
|
||||
"react": "^15.3.2"
|
||||
"react": "^15.4.0-rc.4"
|
||||
},
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"PATENTS",
|
||||
"README.md",
|
||||
"index.js"
|
||||
"index.js",
|
||||
"lib/"
|
||||
]
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "react",
|
||||
"description": "React is a JavaScript library for building user interfaces.",
|
||||
"version": "15.3.2",
|
||||
"version": "15.4.0-rc.4",
|
||||
"keywords": [
|
||||
"react"
|
||||
],
|
||||
|
||||
+12
-3
@@ -2,12 +2,21 @@ Work-in-progress benchmarks.
|
||||
|
||||
## Running the suite
|
||||
|
||||
You'll need two folders to compare, each of them containing `react.min.js` and `react-dom-server.min.js`. You can run `npm run build` at the repo root to get a `build` folder with these files.
|
||||
|
||||
For example, if you want to compare a stable verion against master, you can create folders called `build-stable` and `build-master` and use the benchmark scripts like this:
|
||||
|
||||
```
|
||||
$ ./measure.py react-a.min.js >a.txt
|
||||
$ ./measure.py react-b.min.js >b.txt
|
||||
$ ./analyze.py a.txt b.txt
|
||||
$ ./measure.py build-stable stable.txt build-master master.txt
|
||||
$ ./analyze.py stable.txt master.txt
|
||||
```
|
||||
|
||||
The test measurements (second argument to `analyze`, `master.txt` in this example) will be compared to the control measurements (first argument to `analyze`, `stable.txt` in this example).
|
||||
|
||||
Changes with the `-` sign in the output mean `master` is faster than `stable`.
|
||||
|
||||
You can name folders any way you like, this was just an example.
|
||||
|
||||
## Running one
|
||||
One thing you can do with them is benchmark initial render time for a realistic hierarchy:
|
||||
|
||||
|
||||
+38
-14
@@ -9,12 +9,13 @@
|
||||
import functools
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def _run_js_in_jsc(jit, js, env):
|
||||
return subprocess.check_call(
|
||||
return subprocess.check_output(
|
||||
['jsc', '-e', """
|
||||
function now() {
|
||||
return preciseTime() * 1000;
|
||||
@@ -41,7 +42,7 @@ _run_js_in_jsc_nojit = functools.partial(_run_js_in_jsc, False)
|
||||
|
||||
|
||||
def _run_js_in_node(js, env):
|
||||
return subprocess.check_call(
|
||||
return subprocess.check_output(
|
||||
['node', '-e', """
|
||||
function now() {
|
||||
var hrTime = process.hrtime();
|
||||
@@ -70,13 +71,16 @@ def _run_js_in_node(js, env):
|
||||
|
||||
|
||||
def _measure_ssr_ms(engine, react_path, bench_name, bench_path, measure_warm):
|
||||
engine(
|
||||
return engine(
|
||||
"""
|
||||
var reactCode = readFile(ENV.react_path);
|
||||
var reactCode = readFile(ENV.react_path + '/react.min.js');
|
||||
var reactDOMServerCode = readFile(ENV.react_path + '/react-dom-server.min.js');
|
||||
var START = now();
|
||||
globalEval(reactCode);
|
||||
globalEval(reactDOMServerCode);
|
||||
var END = now();
|
||||
if (typeof React !== 'object') throw new Error('React not laoded');
|
||||
if (typeof React !== 'object') throw new Error('React not loaded');
|
||||
if (typeof ReactDOMServer !== 'object') throw new Error('ReactDOMServer not loaded');
|
||||
report('factory_ms', END - START);
|
||||
|
||||
globalEval(readFile(ENV.bench_path));
|
||||
@@ -84,7 +88,7 @@ def _measure_ssr_ms(engine, react_path, bench_name, bench_path, measure_warm):
|
||||
throw new Error('benchmark not loaded');
|
||||
}
|
||||
var START = now();
|
||||
var html = React.renderToString(React.createElement(Benchmark));
|
||||
var html = ReactDOMServer.renderToString(React.createElement(Benchmark));
|
||||
html.charCodeAt(0); // flatten ropes
|
||||
var END = now();
|
||||
report('ssr_' + ENV.bench_name + '_cold_ms', END - START);
|
||||
@@ -93,12 +97,12 @@ def _measure_ssr_ms(engine, react_path, bench_name, bench_path, measure_warm):
|
||||
var trials = ENV.measure_warm ? 40 : 0;
|
||||
|
||||
for (var i = 0; i < warmup; i++) {
|
||||
React.renderToString(React.createElement(Benchmark));
|
||||
ReactDOMServer.renderToString(React.createElement(Benchmark));
|
||||
}
|
||||
|
||||
for (var i = 0; i < trials; i++) {
|
||||
var START = now();
|
||||
var html = React.renderToString(React.createElement(Benchmark));
|
||||
var html = ReactDOMServer.renderToString(React.createElement(Benchmark));
|
||||
html.charCodeAt(0); // flatten ropes
|
||||
var END = now();
|
||||
report('ssr_' + ENV.bench_name + '_warm_ms', END - START);
|
||||
@@ -114,36 +118,56 @@ def _measure_ssr_ms(engine, react_path, bench_name, bench_path, measure_warm):
|
||||
|
||||
|
||||
def _main():
|
||||
if len(sys.argv) != 2:
|
||||
sys.stderr.write("usage: measure.py react.min.js >out.txt\n")
|
||||
if len(sys.argv) < 2 or len(sys.argv) % 2 == 0:
|
||||
sys.stderr.write("usage: measure.py build-folder-a a.txt build-folder-b b.txt\n")
|
||||
return 1
|
||||
react_path = sys.argv[1]
|
||||
# [(react_path, out_path)]
|
||||
react_paths = sys.argv[1::2]
|
||||
files = [open(out_path, 'w') for out_path in sys.argv[2::2]]
|
||||
|
||||
trials = 30
|
||||
sys.stderr.write("Measuring SSR for PE benchmark (%d trials)\n" % trials)
|
||||
sys.stderr.write("_" * trials + "\n")
|
||||
for i in range(trials):
|
||||
for engine in [
|
||||
_run_js_in_jsc_jit,
|
||||
_run_js_in_jsc_nojit,
|
||||
_run_js_in_node
|
||||
]:
|
||||
_measure_ssr_ms(engine, react_path, 'pe', 'bench-pe-es5.js', False)
|
||||
engines = range(len(react_paths))
|
||||
random.shuffle(engines)
|
||||
for i in engines:
|
||||
out = _measure_ssr_ms(engine, react_paths[i], 'pe', 'bench-pe-es5.js', False)
|
||||
files[i].write(out)
|
||||
sys.stderr.write(".")
|
||||
sys.stderr.flush()
|
||||
sys.stderr.write("\n")
|
||||
sys.stderr.flush()
|
||||
|
||||
# You can set this to a number of trials you want to do with warm JIT.
|
||||
# They are disabled by default because they are slower.
|
||||
trials = 0
|
||||
|
||||
trials = 3
|
||||
sys.stderr.write("Measuring SSR for PE with warm JIT (%d slow trials)\n" % trials)
|
||||
sys.stderr.write("_" * trials + "\n")
|
||||
for i in range(trials):
|
||||
for engine in [
|
||||
_run_js_in_jsc_jit,
|
||||
_run_js_in_jsc_nojit,
|
||||
_run_js_in_node
|
||||
]:
|
||||
_measure_ssr_ms(engine, react_path, 'pe', 'bench-pe-es5.js', True)
|
||||
engines = range(len(react_paths))
|
||||
random.shuffle(engines)
|
||||
for i in engines:
|
||||
out = _measure_ssr_ms(engine, react_paths[i], 'pe', 'bench-pe-es5.js', True)
|
||||
files[i].write(out)
|
||||
sys.stderr.write(".")
|
||||
sys.stderr.flush()
|
||||
sys.stderr.write("\n")
|
||||
sys.stderr.flush()
|
||||
|
||||
for f in files:
|
||||
f.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -25,7 +25,7 @@ function compare(input, output) {
|
||||
|
||||
var oldEnv;
|
||||
|
||||
describe('dev-expression', function() {
|
||||
describe('dev-expression', () => {
|
||||
beforeEach(() => {
|
||||
oldEnv = process.env.NODE_ENV;
|
||||
process.env.NODE_ENV = '';
|
||||
|
||||
@@ -142,5 +142,7 @@
|
||||
"140": "Expected hook events to fire for the child before its parent includes it in onSetChildren().",
|
||||
"141": "Expected onSetChildren() to fire for a container child before its parent includes it in onSetChildren().",
|
||||
"142": "Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (%s has parents %s and %s).",
|
||||
"143": "React.Children.only expected to receive a single React element child."
|
||||
"143": "React.Children.only expected to receive a single React element child.",
|
||||
"144": "Item must have been set",
|
||||
"145": "hostContainerInfo should be populated before getPublicInstance is called."
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Copyright (c) 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var execSync = require('child_process').execSync;
|
||||
|
||||
function escape(value) {
|
||||
return '\'' + value.replace(/'/g, "'\\''") + '\'';
|
||||
}
|
||||
|
||||
var cwd = null;
|
||||
function exec(command) {
|
||||
console.error('>', command.replace(process.env.GITHUB_TOKEN, '************'));
|
||||
return execSync(command, cwd ? {cwd: cwd} : undefined).toString();
|
||||
}
|
||||
|
||||
var isInsideOfTravis = !!process.env.TRAVIS_REPO_SLUG;
|
||||
|
||||
if (isInsideOfTravis) {
|
||||
if (process.env.TRAVIS_BRANCH !== 'master') {
|
||||
console.error('facts-tracker: Branch is not master, exiting...');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (process.env.TRAVIS_PULL_REQUEST !== 'false') {
|
||||
console.error('facts-tracker: This is a pull request, exiting...');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (!process.env.GITHUB_USER || !process.env.GITHUB_TOKEN) {
|
||||
console.error(
|
||||
'In order to use facts-tracker, you need to configure a ' +
|
||||
'few environment variables in order to be able to commit to the ' +
|
||||
'repository. Follow those steps to get you setup:\n' +
|
||||
'\n' +
|
||||
'Go to https://github.com/settings/tokens/new\n' +
|
||||
' - Fill "Token description" with "facts-tracker for ' +
|
||||
process.env.TRAVIS_REPO_SLUG + '"\n' +
|
||||
' - Check "public_repo"\n' +
|
||||
' - Press "Generate Token"\n' +
|
||||
'\n' +
|
||||
'In a different tab, go to https://travis-ci.org/' +
|
||||
process.env.TRAVIS_REPO_SLUG + '/settings\n' +
|
||||
' - Make sure "Build only if .travis.yml is present" is ON\n' +
|
||||
' - Fill "Name" with "GITHUB_TOKEN" and "Value" with the token you ' +
|
||||
'just generated. Press "Add"\n' +
|
||||
' - Fill "Name" with "GITHUB_USER" and "Value" with the name of the ' +
|
||||
'account you generated the token with. Press "Add"\n' +
|
||||
'\n' +
|
||||
'Once this is done, commit anything to the repository to restart ' +
|
||||
'Travis and it should work :)'
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
exec(
|
||||
'echo "machine github.com login $GITHUB_USER password $GITHUB_TOKEN"' +
|
||||
'> ~/.netrc'
|
||||
);
|
||||
exec(
|
||||
'git config --global user.name ' +
|
||||
escape(process.env.GITHUB_USER_NAME || 'facts-tracker')
|
||||
);
|
||||
exec(
|
||||
'git config --global user.email ' +
|
||||
escape(process.env.GITHUB_USER_EMAIL || 'facts-tracker@no-reply.github.com')
|
||||
);
|
||||
}
|
||||
|
||||
if (process.argv.length <= 2) {
|
||||
console.error('Usage: facts-tracker <name1> <value1> <name2> <value2>...');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
function getRepoSlug() {
|
||||
if (isInsideOfTravis) {
|
||||
return process.env.TRAVIS_REPO_SLUG;
|
||||
}
|
||||
|
||||
var remotes = exec('git remote -v').split('\n');
|
||||
for (var i = 0; i < remotes.length; ++i) {
|
||||
var match = remotes[i].match(/^origin\t[^:]+:([^\.]+).+\(fetch\)/);
|
||||
if (match) {
|
||||
return match[1];
|
||||
}
|
||||
}
|
||||
|
||||
console.error('Cannot find repository slug, sorry.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var repoSlug = getRepoSlug();
|
||||
var currentCommitHash = exec('git rev-parse HEAD').trim();
|
||||
var currentTimestamp = new Date().toISOString()
|
||||
.replace('T', ' ')
|
||||
.replace(/\..+/, '');
|
||||
|
||||
function checkoutFactsFolder() {
|
||||
var factsFolder = '../' + repoSlug.split('/')[1] + '-facts';
|
||||
if (!fs.existsSync(factsFolder)) {
|
||||
var escapedRepoURL;
|
||||
if (isInsideOfTravis) {
|
||||
escapedRepoURL = 'https://$GITHUB_TOKEN@github.com/' + escape(repoSlug) + '.git';
|
||||
} else {
|
||||
escapedRepoURL = escape('git@github.com:' + repoSlug + '.git');
|
||||
}
|
||||
|
||||
exec(
|
||||
'git clone ' +
|
||||
'--branch facts ' +
|
||||
'--depth=5 ' +
|
||||
escapedRepoURL + ' ' +
|
||||
escape(factsFolder)
|
||||
);
|
||||
}
|
||||
|
||||
cwd = path.resolve(factsFolder);
|
||||
exec('git fetch');
|
||||
if (exec('git status --porcelain')) {
|
||||
console.error('facts-tracker: `git status` is not clean, aborting.');
|
||||
process.exit(1);
|
||||
}
|
||||
exec('git rebase origin/facts');
|
||||
}
|
||||
checkoutFactsFolder();
|
||||
|
||||
for (var i = 2; i < process.argv.length; i += 2) {
|
||||
var name = process.argv[i].trim();
|
||||
var value = process.argv[i + 1];
|
||||
if (value.indexOf('\n') !== -1) {
|
||||
console.error(
|
||||
'facts-tracker: skipping', name,
|
||||
'as the value contains new lines:', value
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
var filename = name + '.txt';
|
||||
try {
|
||||
var lastLine = exec('tail -n 1 ' + escape(filename));
|
||||
} catch (e) {
|
||||
// ignore error
|
||||
}
|
||||
var lastValue = lastLine && lastLine
|
||||
.replace(/^[^\t]+\t[^\t]+\t/, '') // commit hash \t timestamp \t
|
||||
.slice(0, -1); // trailing \n
|
||||
|
||||
if (value !== lastValue) {
|
||||
fs.appendFileSync(
|
||||
path.resolve(cwd, filename),
|
||||
currentCommitHash + '\t' + currentTimestamp + '\t' + value + '\n'
|
||||
);
|
||||
}
|
||||
|
||||
console.log(name);
|
||||
console.log(lastValue);
|
||||
console.log(value);
|
||||
}
|
||||
|
||||
if (exec('git status --porcelain')) {
|
||||
exec('git add --all');
|
||||
exec('git commit -m ' + escape('Adding facts for ' + currentCommitHash));
|
||||
exec('git push origin facts');
|
||||
} else {
|
||||
console.error('facts-tracker: nothing to update');
|
||||
}
|
||||
cwd = null;
|
||||
@@ -1,2 +1,11 @@
|
||||
/* eslint-disable */
|
||||
global.__DEV__ = true;
|
||||
|
||||
// For testing DOM Fiber, we synchronously invoke all the scheduling.
|
||||
global.requestAnimationFrame = function(callback) {
|
||||
callback();
|
||||
};
|
||||
|
||||
global.requestIdleCallback = function(callback) {
|
||||
callback({ timeRemaining() { return Infinity; } });
|
||||
};
|
||||
File renamed without changes.
@@ -1,5 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
// We want to globally mock this but jest doesn't let us do that by default
|
||||
// for a file that already exists. So we have to explicitly mock it.
|
||||
jest.mock('ReactDOM');
|
||||
|
||||
var env = jasmine.getEnv();
|
||||
|
||||
var callCount = 0;
|
||||
|
||||
+1
-1
@@ -11,4 +11,4 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = '15.3.2';
|
||||
module.exports = '15.4.0-rc.4';
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactAddonsDOMDependencies
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var ReactDOM = require('ReactDOM');
|
||||
var ReactInstanceMap = require('ReactInstanceMap');
|
||||
|
||||
exports.getReactDOM = function() {
|
||||
return ReactDOM;
|
||||
};
|
||||
|
||||
exports.getReactInstanceMap = function() {
|
||||
return ReactInstanceMap;
|
||||
};
|
||||
|
||||
if (__DEV__) {
|
||||
var ReactPerf = require('ReactPerf');
|
||||
var ReactTestUtils = require('ReactTestUtils');
|
||||
|
||||
exports.getReactPerf = function() {
|
||||
return ReactPerf;
|
||||
};
|
||||
|
||||
exports.getReactTestUtils = function() {
|
||||
return ReactTestUtils;
|
||||
};
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
var LinkedStateMixin = require('LinkedStateMixin');
|
||||
var React = require('React');
|
||||
var ReactAddonsDOMDependencies = require('ReactAddonsDOMDependencies');
|
||||
var ReactComponentWithPureRenderMixin =
|
||||
require('ReactComponentWithPureRenderMixin');
|
||||
var ReactCSSTransitionGroup = require('ReactCSSTransitionGroup');
|
||||
@@ -34,8 +35,20 @@ React.addons = {
|
||||
};
|
||||
|
||||
if (__DEV__) {
|
||||
React.addons.Perf = require('ReactPerf');
|
||||
React.addons.TestUtils = require('ReactTestUtils');
|
||||
// For the UMD build we get these lazily from the global since they're tied
|
||||
// to the DOM renderer and it hasn't loaded yet.
|
||||
Object.defineProperty(React.addons, 'Perf', {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return ReactAddonsDOMDependencies.getReactPerf();
|
||||
},
|
||||
});
|
||||
Object.defineProperty(React.addons, 'TestUtils', {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return ReactAddonsDOMDependencies.getReactTestUtils();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = React;
|
||||
@@ -15,16 +15,16 @@ var React;
|
||||
var ReactComponentWithPureRenderMixin;
|
||||
var ReactTestUtils;
|
||||
|
||||
describe('ReactComponentWithPureRenderMixin', function() {
|
||||
describe('ReactComponentWithPureRenderMixin', () => {
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactComponentWithPureRenderMixin =
|
||||
require('ReactComponentWithPureRenderMixin');
|
||||
ReactTestUtils = require('ReactTestUtils');
|
||||
});
|
||||
|
||||
it('provides a default shouldComponentUpdate implementation', function() {
|
||||
it('provides a default shouldComponentUpdate implementation', () => {
|
||||
var renderCalls = 0;
|
||||
class PlasticWrap extends React.Component {
|
||||
constructor(props, context) {
|
||||
@@ -97,7 +97,7 @@ describe('ReactComponentWithPureRenderMixin', function() {
|
||||
expect(renderCalls).toBe(4);
|
||||
});
|
||||
|
||||
it('does not do a deep comparison', function() {
|
||||
it('does not do a deep comparison', () => {
|
||||
function getInitialState() {
|
||||
return {
|
||||
foo: [1, 2, 3],
|
||||
|
||||
@@ -15,15 +15,15 @@ var React;
|
||||
var ReactDOM;
|
||||
var ReactFragment;
|
||||
|
||||
describe('ReactFragment', function() {
|
||||
describe('ReactFragment', () => {
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
ReactFragment = require('ReactFragment');
|
||||
});
|
||||
|
||||
it('should throw if a plain object is used as a child', function() {
|
||||
it('should throw if a plain object is used as a child', () => {
|
||||
var children = {
|
||||
x: <span />,
|
||||
y: <span />,
|
||||
@@ -39,7 +39,7 @@ describe('ReactFragment', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if a plain object even if it is in an owner', function() {
|
||||
it('should throw if a plain object even if it is in an owner', () => {
|
||||
class Foo extends React.Component {
|
||||
render() {
|
||||
var children = {
|
||||
@@ -59,7 +59,7 @@ describe('ReactFragment', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if a plain object looks like an old element', function() {
|
||||
it('should throw if a plain object looks like an old element', () => {
|
||||
var oldEl = {_isReactElement: true, type: 'span', props: {}};
|
||||
var container = document.createElement('div');
|
||||
expect(() => ReactDOM.render(<div>{oldEl}</div>, container)).toThrowError(
|
||||
@@ -70,7 +70,7 @@ describe('ReactFragment', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('warns for numeric keys on objects as children', function() {
|
||||
it('warns for numeric keys on objects as children', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
ReactFragment.create({1: <span />, 2: <span />});
|
||||
@@ -81,7 +81,7 @@ describe('ReactFragment', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if passing null to createFragment', function() {
|
||||
it('should warn if passing null to createFragment', () => {
|
||||
spyOn(console, 'error');
|
||||
ReactFragment.create(null);
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
@@ -90,7 +90,7 @@ describe('ReactFragment', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if passing an array to createFragment', function() {
|
||||
it('should warn if passing an array to createFragment', () => {
|
||||
spyOn(console, 'error');
|
||||
ReactFragment.create([]);
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
@@ -99,7 +99,7 @@ describe('ReactFragment', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if passing a ReactElement to createFragment', function() {
|
||||
it('should warn if passing a ReactElement to createFragment', () => {
|
||||
spyOn(console, 'error');
|
||||
ReactFragment.create(<div />);
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
|
||||
@@ -16,9 +16,9 @@ var ReactDOM = require('ReactDOM');
|
||||
var ReactTestUtils = require('ReactTestUtils');
|
||||
var renderSubtreeIntoContainer = require('renderSubtreeIntoContainer');
|
||||
|
||||
describe('renderSubtreeIntoContainer', function() {
|
||||
describe('renderSubtreeIntoContainer', () => {
|
||||
|
||||
it('should pass context when rendering subtree elsewhere', function() {
|
||||
it('should pass context when rendering subtree elsewhere', () => {
|
||||
var portal = document.createElement('div');
|
||||
|
||||
class Component extends React.Component {
|
||||
@@ -57,7 +57,7 @@ describe('renderSubtreeIntoContainer', function() {
|
||||
expect(portal.firstChild.innerHTML).toBe('bar');
|
||||
});
|
||||
|
||||
it('should throw if parentComponent is invalid', function() {
|
||||
it('should throw if parentComponent is invalid', () => {
|
||||
var portal = document.createElement('div');
|
||||
|
||||
class Component extends React.Component {
|
||||
@@ -93,7 +93,7 @@ describe('renderSubtreeIntoContainer', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('should update context if it changes due to setState', function() {
|
||||
it('should update context if it changes due to setState', () => {
|
||||
var container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
var portal = document.createElement('div');
|
||||
@@ -145,7 +145,7 @@ describe('renderSubtreeIntoContainer', function() {
|
||||
expect(portal.firstChild.innerHTML).toBe('changed-changed');
|
||||
});
|
||||
|
||||
it('should update context if it changes due to re-render', function() {
|
||||
it('should update context if it changes due to re-render', () => {
|
||||
var container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
var portal = document.createElement('div');
|
||||
|
||||
@@ -13,62 +13,62 @@
|
||||
|
||||
var update = require('update');
|
||||
|
||||
describe('update', function() {
|
||||
describe('update', () => {
|
||||
|
||||
describe('$push', function() {
|
||||
it('pushes', function() {
|
||||
describe('$push', () => {
|
||||
it('pushes', () => {
|
||||
expect(update([1], {$push: [7]})).toEqual([1, 7]);
|
||||
});
|
||||
it('does not mutate the original object', function() {
|
||||
it('does not mutate the original object', () => {
|
||||
var obj = [1];
|
||||
update(obj, {$push: [7]});
|
||||
expect(obj).toEqual([1]);
|
||||
});
|
||||
it('only pushes an array', function() {
|
||||
it('only pushes an array', () => {
|
||||
expect(update.bind(null, [], {$push: 7})).toThrowError(
|
||||
'update(): expected spec of $push to be an array; got 7. Did you ' +
|
||||
'forget to wrap your parameter in an array?'
|
||||
);
|
||||
});
|
||||
it('only pushes unto an array', function() {
|
||||
it('only pushes unto an array', () => {
|
||||
expect(update.bind(null, 1, {$push: 7})).toThrowError(
|
||||
'update(): expected target of $push to be an array; got 1.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('$unshift', function() {
|
||||
it('unshifts', function() {
|
||||
describe('$unshift', () => {
|
||||
it('unshifts', () => {
|
||||
expect(update([1], {$unshift: [7]})).toEqual([7, 1]);
|
||||
});
|
||||
it('does not mutate the original object', function() {
|
||||
it('does not mutate the original object', () => {
|
||||
var obj = [1];
|
||||
update(obj, {$unshift: [7]});
|
||||
expect(obj).toEqual([1]);
|
||||
});
|
||||
it('only unshifts an array', function() {
|
||||
it('only unshifts an array', () => {
|
||||
expect(update.bind(null, [], {$unshift: 7})).toThrowError(
|
||||
'update(): expected spec of $unshift to be an array; got 7. Did you ' +
|
||||
'forget to wrap your parameter in an array?'
|
||||
);
|
||||
});
|
||||
it('only unshifts unto an array', function() {
|
||||
it('only unshifts unto an array', () => {
|
||||
expect(update.bind(null, 1, {$unshift: 7})).toThrowError(
|
||||
'update(): expected target of $unshift to be an array; got 1.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('$splice', function() {
|
||||
it('splices', function() {
|
||||
describe('$splice', () => {
|
||||
it('splices', () => {
|
||||
expect(update([1, 4, 3], {$splice: [[1, 1, 2]]})).toEqual([1, 2, 3]);
|
||||
});
|
||||
it('does not mutate the original object', function() {
|
||||
it('does not mutate the original object', () => {
|
||||
var obj = [1, 4, 3];
|
||||
update(obj, {$splice: [[1, 1, 2]]});
|
||||
expect(obj).toEqual([1, 4, 3]);
|
||||
});
|
||||
it('only splices an array of arrays', function() {
|
||||
it('only splices an array of arrays', () => {
|
||||
expect(update.bind(null, [], {$splice: 1})).toThrowError(
|
||||
'update(): expected spec of $splice to be an array of arrays; got 1. ' +
|
||||
'Did you forget to wrap your parameters in an array?'
|
||||
@@ -78,65 +78,65 @@ describe('update', function() {
|
||||
'Did you forget to wrap your parameters in an array?'
|
||||
);
|
||||
});
|
||||
it('only splices unto an array', function() {
|
||||
it('only splices unto an array', () => {
|
||||
expect(update.bind(null, 1, {$splice: 7})).toThrowError(
|
||||
'Expected $splice target to be an array; got 1'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('$merge', function() {
|
||||
it('merges', function() {
|
||||
describe('$merge', () => {
|
||||
it('merges', () => {
|
||||
expect(update({a: 'b'}, {$merge: {c: 'd'}})).toEqual({a: 'b', c: 'd'});
|
||||
});
|
||||
it('does not mutate the original object', function() {
|
||||
it('does not mutate the original object', () => {
|
||||
var obj = {a: 'b'};
|
||||
update(obj, {$merge: {c: 'd'}});
|
||||
expect(obj).toEqual({a: 'b'});
|
||||
});
|
||||
it('only merges with an object', function() {
|
||||
it('only merges with an object', () => {
|
||||
expect(update.bind(null, {}, {$merge: 7})).toThrowError(
|
||||
'update(): $merge expects a spec of type \'object\'; got 7'
|
||||
);
|
||||
});
|
||||
it('only merges with an object', function() {
|
||||
it('only merges with an object', () => {
|
||||
expect(update.bind(null, 7, {$merge: {a: 'b'}})).toThrowError(
|
||||
'update(): $merge expects a target of type \'object\'; got 7'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('$set', function() {
|
||||
it('sets', function() {
|
||||
describe('$set', () => {
|
||||
it('sets', () => {
|
||||
expect(update({a: 'b'}, {$set: {c: 'd'}})).toEqual({c: 'd'});
|
||||
});
|
||||
it('does not mutate the original object', function() {
|
||||
it('does not mutate the original object', () => {
|
||||
var obj = {a: 'b'};
|
||||
update(obj, {$set: {c: 'd'}});
|
||||
expect(obj).toEqual({a: 'b'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('$apply', function() {
|
||||
describe('$apply', () => {
|
||||
var applier = function(node) {
|
||||
return {v: node.v * 2};
|
||||
};
|
||||
it('applies', function() {
|
||||
it('applies', () => {
|
||||
expect(update({v: 2}, {$apply: applier})).toEqual({v: 4});
|
||||
});
|
||||
it('does not mutate the original object', function() {
|
||||
it('does not mutate the original object', () => {
|
||||
var obj = {v: 2};
|
||||
update(obj, {$apply: applier});
|
||||
expect(obj).toEqual({v: 2});
|
||||
});
|
||||
it('only applies a function', function() {
|
||||
it('only applies a function', () => {
|
||||
expect(update.bind(null, 2, {$apply: 123})).toThrowError(
|
||||
'update(): expected spec of $apply to be a function; got 123.'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should support deep updates', function() {
|
||||
it('should support deep updates', () => {
|
||||
expect(update({
|
||||
a: 'b',
|
||||
c: {
|
||||
@@ -169,7 +169,7 @@ describe('update', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should require a command', function() {
|
||||
it('should require a command', () => {
|
||||
expect(update.bind(null, {a: 'b'}, {a: 'c'})).toThrowError(
|
||||
'update(): You provided a key path to update() that did not contain ' +
|
||||
'one of $push, $unshift, $splice, $set, $merge, $apply. Did you ' +
|
||||
@@ -177,7 +177,7 @@ describe('update', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should perform safe hasOwnProperty check', function() {
|
||||
it('should perform safe hasOwnProperty check', () => {
|
||||
expect(update({}, {'hasOwnProperty': {$set: 'a'}})).toEqual({
|
||||
'hasOwnProperty': 'a',
|
||||
});
|
||||
|
||||
@@ -24,8 +24,7 @@ var LinkedStateMixin = {
|
||||
* ReactLink will have the current value of this.state[key] and will call
|
||||
* setState() when a change is requested.
|
||||
*
|
||||
* @param {string} key state key to update. Note: you may want to use keyOf()
|
||||
* if you're using Google Closure Compiler advanced mode.
|
||||
* @param {string} key state key to update.
|
||||
* @return {ReactLink} ReactLink instance linking to the state.
|
||||
*/
|
||||
linkState: function(key) {
|
||||
|
||||
@@ -12,18 +12,18 @@
|
||||
'use strict';
|
||||
|
||||
|
||||
describe('LinkedStateMixin', function() {
|
||||
describe('LinkedStateMixin', () => {
|
||||
var LinkedStateMixin;
|
||||
var React;
|
||||
var ReactTestUtils;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
LinkedStateMixin = require('LinkedStateMixin');
|
||||
React = require('React');
|
||||
ReactTestUtils = require('ReactTestUtils');
|
||||
});
|
||||
|
||||
it('should create a ReactLink for state', function() {
|
||||
it('should create a ReactLink for state', () => {
|
||||
var Component = React.createClass({
|
||||
mixins: [LinkedStateMixin],
|
||||
|
||||
|
||||
@@ -14,12 +14,11 @@
|
||||
var emptyFunction = require('emptyFunction');
|
||||
var LinkPropTypes = require('ReactLink').PropTypes;
|
||||
var React = require('React');
|
||||
var ReactPropTypeLocations = require('ReactPropTypeLocations');
|
||||
var ReactPropTypesSecret = require('ReactPropTypesSecret');
|
||||
|
||||
var invalidMessage = 'Invalid prop `testProp` supplied to `testComponent`.';
|
||||
var requiredMessage =
|
||||
'Required prop `testProp` was not specified in `testComponent`.';
|
||||
var requiredMessage = 'The prop `testProp` is marked as required in ' +
|
||||
'`testComponent`, but its value is `undefined`.';
|
||||
|
||||
function typeCheckFail(declaration, value, message) {
|
||||
var props = {testProp: value};
|
||||
@@ -27,7 +26,7 @@ function typeCheckFail(declaration, value, message) {
|
||||
props,
|
||||
'testProp',
|
||||
'testComponent',
|
||||
ReactPropTypeLocations.prop,
|
||||
'prop',
|
||||
null,
|
||||
ReactPropTypesSecret
|
||||
);
|
||||
@@ -41,38 +40,42 @@ function typeCheckPass(declaration, value) {
|
||||
props,
|
||||
'testProp',
|
||||
'testComponent',
|
||||
ReactPropTypeLocations.prop,
|
||||
'prop',
|
||||
null,
|
||||
ReactPropTypesSecret
|
||||
);
|
||||
expect(error).toBe(null);
|
||||
}
|
||||
|
||||
describe('ReactLink', function() {
|
||||
it('should fail if the argument does not implement the Link API', function() {
|
||||
describe('ReactLink', () => {
|
||||
it('should fail if the argument does not implement the Link API', () => {
|
||||
typeCheckFail(
|
||||
LinkPropTypes.link(React.PropTypes.any),
|
||||
{},
|
||||
'Required prop `testProp.value` was not specified in `testComponent`.'
|
||||
'The prop `testProp.value` is marked as required in `testComponent`, ' +
|
||||
'but its value is `undefined`.'
|
||||
);
|
||||
typeCheckFail(
|
||||
LinkPropTypes.link(React.PropTypes.any),
|
||||
{value: 123},
|
||||
'Required prop `testProp.requestChange` was not specified in `testComponent`.'
|
||||
'The prop `testProp.requestChange` is marked as required in ' +
|
||||
'`testComponent`, but its value is `undefined`.'
|
||||
);
|
||||
typeCheckFail(
|
||||
LinkPropTypes.link(React.PropTypes.any),
|
||||
{requestChange: emptyFunction},
|
||||
'Required prop `testProp.value` was not specified in `testComponent`.'
|
||||
'The prop `testProp.value` is marked as required in `testComponent`, ' +
|
||||
'but its value is `undefined`.'
|
||||
);
|
||||
typeCheckFail(
|
||||
LinkPropTypes.link(React.PropTypes.any),
|
||||
{value: null, requestChange: null},
|
||||
'Required prop `testProp.value` was not specified in `testComponent`.'
|
||||
'The prop `testProp.value` is marked as required in `testComponent`, ' +
|
||||
'but its value is `null`.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should allow valid links even if no type was specified', function() {
|
||||
it('should allow valid links even if no type was specified', () => {
|
||||
typeCheckPass(
|
||||
LinkPropTypes.link(),
|
||||
{value: 42, requestChange: emptyFunction}
|
||||
@@ -83,14 +86,14 @@ describe('ReactLink', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow no link to be passed at all', function() {
|
||||
it('should allow no link to be passed at all', () => {
|
||||
typeCheckPass(
|
||||
LinkPropTypes.link(React.PropTypes.string),
|
||||
undefined
|
||||
);
|
||||
});
|
||||
|
||||
it('should allow valid links with correct value format', function() {
|
||||
it('should allow valid links with correct value format', () => {
|
||||
typeCheckPass(
|
||||
LinkPropTypes.link(React.PropTypes.any),
|
||||
{value: 42, requestChange: emptyFunction}
|
||||
@@ -105,7 +108,7 @@ describe('ReactLink', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should fail if the link`s value type does not match', function() {
|
||||
it('should fail if the link`s value type does not match', () => {
|
||||
typeCheckFail(
|
||||
LinkPropTypes.link(React.PropTypes.string),
|
||||
{value: 123, requestChange: emptyFunction},
|
||||
@@ -114,20 +117,22 @@ describe('ReactLink', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should be implicitly optional and not warn without values', function() {
|
||||
it('should be implicitly optional and not warn without values', () => {
|
||||
typeCheckPass(LinkPropTypes.link(), null);
|
||||
typeCheckPass(LinkPropTypes.link(), undefined);
|
||||
typeCheckPass(LinkPropTypes.link(React.PropTypes.string), null);
|
||||
typeCheckPass(LinkPropTypes.link(React.PropTypes.string), undefined);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(LinkPropTypes.link().isRequired, null, requiredMessage);
|
||||
it('should warn for missing required values', () => {
|
||||
var specifiedButIsNullMsg = 'The prop `testProp` is marked as required ' +
|
||||
'in `testComponent`, but its value is `null`.';
|
||||
typeCheckFail(LinkPropTypes.link().isRequired, null, specifiedButIsNullMsg);
|
||||
typeCheckFail(LinkPropTypes.link().isRequired, undefined, requiredMessage);
|
||||
typeCheckFail(
|
||||
LinkPropTypes.link(React.PropTypes.string).isRequired,
|
||||
null,
|
||||
requiredMessage
|
||||
specifiedButIsNullMsg
|
||||
);
|
||||
typeCheckFail(
|
||||
LinkPropTypes.link(React.PropTypes.string).isRequired,
|
||||
@@ -136,7 +141,7 @@ describe('ReactLink', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should be compatible with React.PropTypes.oneOfType', function() {
|
||||
it('should be compatible with React.PropTypes.oneOfType', () => {
|
||||
typeCheckPass(
|
||||
React.PropTypes.oneOfType([LinkPropTypes.link(React.PropTypes.number)]),
|
||||
{value: 123, requestChange: emptyFunction}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule shallowCompare
|
||||
*/
|
||||
* @providesModule shallowCompare
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@@ -46,10 +46,10 @@ function createTransitionTimeoutPropValidator(transitionType) {
|
||||
* enters or leaves the DOM.
|
||||
* See https://facebook.github.io/react/docs/animation.html#high-level-api-reactcsstransitiongroup
|
||||
*/
|
||||
var ReactCSSTransitionGroup = React.createClass({
|
||||
displayName: 'ReactCSSTransitionGroup',
|
||||
class ReactCSSTransitionGroup extends React.Component {
|
||||
static displayName = 'ReactCSSTransitionGroup';
|
||||
|
||||
propTypes: {
|
||||
static propTypes = {
|
||||
transitionName: ReactCSSTransitionGroupChild.propTypes.name,
|
||||
|
||||
transitionAppear: React.PropTypes.bool,
|
||||
@@ -58,17 +58,15 @@ var ReactCSSTransitionGroup = React.createClass({
|
||||
transitionAppearTimeout: createTransitionTimeoutPropValidator('Appear'),
|
||||
transitionEnterTimeout: createTransitionTimeoutPropValidator('Enter'),
|
||||
transitionLeaveTimeout: createTransitionTimeoutPropValidator('Leave'),
|
||||
},
|
||||
};
|
||||
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
transitionAppear: false,
|
||||
transitionEnter: true,
|
||||
transitionLeave: true,
|
||||
};
|
||||
},
|
||||
static defaultProps = {
|
||||
transitionAppear: false,
|
||||
transitionEnter: true,
|
||||
transitionLeave: true,
|
||||
};
|
||||
|
||||
_wrapChild: function(child) {
|
||||
_wrapChild = (child) => {
|
||||
// We need to provide this childFactory so that
|
||||
// ReactCSSTransitionGroupChild can receive updates to name, enter, and
|
||||
// leave while it is leaving.
|
||||
@@ -85,14 +83,14 @@ var ReactCSSTransitionGroup = React.createClass({
|
||||
},
|
||||
child
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
render: function() {
|
||||
render() {
|
||||
return React.createElement(
|
||||
ReactTransitionGroup,
|
||||
Object.assign({}, this.props, {childFactory: this._wrapChild})
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ReactCSSTransitionGroup;
|
||||
@@ -12,7 +12,7 @@
|
||||
'use strict';
|
||||
|
||||
var React = require('React');
|
||||
var ReactDOM = require('ReactDOM');
|
||||
var ReactAddonsDOMDependencies = require('ReactAddonsDOMDependencies');
|
||||
|
||||
var CSSCore = require('CSSCore');
|
||||
var ReactTransitionEvents = require('ReactTransitionEvents');
|
||||
@@ -54,7 +54,7 @@ var ReactCSSTransitionGroupChild = React.createClass({
|
||||
},
|
||||
|
||||
transition: function(animationType, finishCallback, userSpecifiedDelay) {
|
||||
var node = ReactDOM.findDOMNode(this);
|
||||
var node = ReactAddonsDOMDependencies.getReactDOM().findDOMNode(this);
|
||||
|
||||
if (!node) {
|
||||
if (finishCallback) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
'use strict';
|
||||
|
||||
var React = require('React');
|
||||
var ReactInstanceMap = require('ReactInstanceMap');
|
||||
var ReactAddonsDOMDependencies = require('ReactAddonsDOMDependencies');
|
||||
var ReactTransitionChildMapping = require('ReactTransitionChildMapping');
|
||||
|
||||
var emptyFunction = require('emptyFunction');
|
||||
@@ -22,49 +22,45 @@ var emptyFunction = require('emptyFunction');
|
||||
* special lifecycle hooks are called.
|
||||
* See https://facebook.github.io/react/docs/animation.html#low-level-api-reacttransitiongroup
|
||||
*/
|
||||
var ReactTransitionGroup = React.createClass({
|
||||
displayName: 'ReactTransitionGroup',
|
||||
class ReactTransitionGroup extends React.Component {
|
||||
static displayName = 'ReactTransitionGroup';
|
||||
|
||||
propTypes: {
|
||||
static propTypes = {
|
||||
component: React.PropTypes.any,
|
||||
childFactory: React.PropTypes.func,
|
||||
},
|
||||
};
|
||||
|
||||
getDefaultProps: function() {
|
||||
return {
|
||||
component: 'span',
|
||||
childFactory: emptyFunction.thatReturnsArgument,
|
||||
};
|
||||
},
|
||||
static defaultProps = {
|
||||
component: 'span',
|
||||
childFactory: emptyFunction.thatReturnsArgument,
|
||||
};
|
||||
|
||||
getInitialState: function() {
|
||||
return {
|
||||
// TODO: can we get useful debug information to show at this point?
|
||||
children: ReactTransitionChildMapping.getChildMapping(this.props.children),
|
||||
};
|
||||
},
|
||||
state = {
|
||||
// TODO: can we get useful debug information to show at this point?
|
||||
children: ReactTransitionChildMapping.getChildMapping(this.props.children),
|
||||
};
|
||||
|
||||
componentWillMount: function() {
|
||||
componentWillMount() {
|
||||
this.currentlyTransitioningKeys = {};
|
||||
this.keysToEnter = [];
|
||||
this.keysToLeave = [];
|
||||
},
|
||||
}
|
||||
|
||||
componentDidMount: function() {
|
||||
componentDidMount() {
|
||||
var initialChildMapping = this.state.children;
|
||||
for (var key in initialChildMapping) {
|
||||
if (initialChildMapping[key]) {
|
||||
this.performAppear(key);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
componentWillReceiveProps: function(nextProps) {
|
||||
componentWillReceiveProps(nextProps) {
|
||||
var nextChildMapping;
|
||||
if (__DEV__) {
|
||||
nextChildMapping = ReactTransitionChildMapping.getChildMapping(
|
||||
nextProps.children,
|
||||
ReactInstanceMap.get(this)._debugID
|
||||
ReactAddonsDOMDependencies.getReactInstanceMap().get(this)._debugID
|
||||
);
|
||||
} else {
|
||||
nextChildMapping = ReactTransitionChildMapping.getChildMapping(
|
||||
@@ -99,9 +95,9 @@ var ReactTransitionGroup = React.createClass({
|
||||
}
|
||||
|
||||
// If we want to someday check for reordering, we could do it here.
|
||||
},
|
||||
}
|
||||
|
||||
componentDidUpdate: function() {
|
||||
componentDidUpdate() {
|
||||
var keysToEnter = this.keysToEnter;
|
||||
this.keysToEnter = [];
|
||||
keysToEnter.forEach(this.performEnter);
|
||||
@@ -109,9 +105,9 @@ var ReactTransitionGroup = React.createClass({
|
||||
var keysToLeave = this.keysToLeave;
|
||||
this.keysToLeave = [];
|
||||
keysToLeave.forEach(this.performLeave);
|
||||
},
|
||||
}
|
||||
|
||||
performAppear: function(key) {
|
||||
performAppear = (key) => {
|
||||
this.currentlyTransitioningKeys[key] = true;
|
||||
|
||||
var component = this.refs[key];
|
||||
@@ -123,9 +119,9 @@ var ReactTransitionGroup = React.createClass({
|
||||
} else {
|
||||
this._handleDoneAppearing(key);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
_handleDoneAppearing: function(key) {
|
||||
_handleDoneAppearing = (key) => {
|
||||
var component = this.refs[key];
|
||||
if (component.componentDidAppear) {
|
||||
component.componentDidAppear();
|
||||
@@ -137,7 +133,7 @@ var ReactTransitionGroup = React.createClass({
|
||||
if (__DEV__) {
|
||||
currentChildMapping = ReactTransitionChildMapping.getChildMapping(
|
||||
this.props.children,
|
||||
ReactInstanceMap.get(this)._debugID
|
||||
ReactAddonsDOMDependencies.getReactInstanceMap().get(this)._debugID
|
||||
);
|
||||
} else {
|
||||
currentChildMapping = ReactTransitionChildMapping.getChildMapping(
|
||||
@@ -149,9 +145,9 @@ var ReactTransitionGroup = React.createClass({
|
||||
// This was removed before it had fully appeared. Remove it.
|
||||
this.performLeave(key);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
performEnter: function(key) {
|
||||
performEnter = (key) => {
|
||||
this.currentlyTransitioningKeys[key] = true;
|
||||
|
||||
var component = this.refs[key];
|
||||
@@ -163,9 +159,9 @@ var ReactTransitionGroup = React.createClass({
|
||||
} else {
|
||||
this._handleDoneEntering(key);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
_handleDoneEntering: function(key) {
|
||||
_handleDoneEntering = (key) => {
|
||||
var component = this.refs[key];
|
||||
if (component.componentDidEnter) {
|
||||
component.componentDidEnter();
|
||||
@@ -177,7 +173,7 @@ var ReactTransitionGroup = React.createClass({
|
||||
if (__DEV__) {
|
||||
currentChildMapping = ReactTransitionChildMapping.getChildMapping(
|
||||
this.props.children,
|
||||
ReactInstanceMap.get(this)._debugID
|
||||
ReactAddonsDOMDependencies.getReactInstanceMap().get(this)._debugID
|
||||
);
|
||||
} else {
|
||||
currentChildMapping = ReactTransitionChildMapping.getChildMapping(
|
||||
@@ -189,9 +185,9 @@ var ReactTransitionGroup = React.createClass({
|
||||
// This was removed before it had fully entered. Remove it.
|
||||
this.performLeave(key);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
performLeave: function(key) {
|
||||
performLeave = (key) => {
|
||||
this.currentlyTransitioningKeys[key] = true;
|
||||
|
||||
var component = this.refs[key];
|
||||
@@ -203,9 +199,9 @@ var ReactTransitionGroup = React.createClass({
|
||||
// is done.
|
||||
this._handleDoneLeaving(key);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
_handleDoneLeaving: function(key) {
|
||||
_handleDoneLeaving = (key) => {
|
||||
var component = this.refs[key];
|
||||
|
||||
if (component.componentDidLeave) {
|
||||
@@ -218,7 +214,7 @@ var ReactTransitionGroup = React.createClass({
|
||||
if (__DEV__) {
|
||||
currentChildMapping = ReactTransitionChildMapping.getChildMapping(
|
||||
this.props.children,
|
||||
ReactInstanceMap.get(this)._debugID
|
||||
ReactAddonsDOMDependencies.getReactInstanceMap().get(this)._debugID
|
||||
);
|
||||
} else {
|
||||
currentChildMapping = ReactTransitionChildMapping.getChildMapping(
|
||||
@@ -236,9 +232,9 @@ var ReactTransitionGroup = React.createClass({
|
||||
return {children: newChildren};
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
render: function() {
|
||||
render() {
|
||||
// TODO: we could get rid of the need for the wrapper node
|
||||
// by cloning a single child
|
||||
var childrenToRender = [];
|
||||
@@ -274,7 +270,7 @@ var ReactTransitionGroup = React.createClass({
|
||||
props,
|
||||
childrenToRender
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ReactTransitionGroup;
|
||||
@@ -19,10 +19,10 @@ var ReactCSSTransitionGroup;
|
||||
|
||||
// Most of the real functionality is covered in other unit tests, this just
|
||||
// makes sure we're wired up correctly.
|
||||
describe('ReactCSSTransitionGroup', function() {
|
||||
describe('ReactCSSTransitionGroup', () => {
|
||||
var container;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
@@ -32,7 +32,7 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
spyOn(console, 'error');
|
||||
});
|
||||
|
||||
it('should warn if timeouts aren\'t specified', function() {
|
||||
it('should warn if timeouts aren\'t specified', () => {
|
||||
ReactDOM.render(
|
||||
<ReactCSSTransitionGroup
|
||||
transitionName="yolo"
|
||||
@@ -48,7 +48,7 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
});
|
||||
|
||||
it('should not warn if timeouts is zero', function() {
|
||||
it('should not warn if timeouts is zero', () => {
|
||||
ReactDOM.render(
|
||||
<ReactCSSTransitionGroup
|
||||
transitionName="yolo"
|
||||
@@ -64,7 +64,7 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('should clean-up silently after the timeout elapses', function() {
|
||||
it('should clean-up silently after the timeout elapses', () => {
|
||||
var a = ReactDOM.render(
|
||||
<ReactCSSTransitionGroup
|
||||
transitionName="yolo"
|
||||
@@ -110,7 +110,7 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
expect(ReactDOM.findDOMNode(a).childNodes[0].id).toBe('two');
|
||||
});
|
||||
|
||||
it('should keep both sets of DOM nodes around', function() {
|
||||
it('should keep both sets of DOM nodes around', () => {
|
||||
var a = ReactDOM.render(
|
||||
<ReactCSSTransitionGroup transitionName="yolo">
|
||||
<span key="one" id="one" />
|
||||
@@ -129,7 +129,7 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
expect(ReactDOM.findDOMNode(a).childNodes[1].id).toBe('one');
|
||||
});
|
||||
|
||||
it('should switch transitionLeave from false to true', function() {
|
||||
it('should switch transitionLeave from false to true', () => {
|
||||
var a = ReactDOM.render(
|
||||
<ReactCSSTransitionGroup
|
||||
transitionName="yolo"
|
||||
@@ -164,14 +164,14 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
expect(ReactDOM.findDOMNode(a).childNodes[1].id).toBe('two');
|
||||
});
|
||||
|
||||
it('should work with no children', function() {
|
||||
it('should work with no children', () => {
|
||||
ReactDOM.render(
|
||||
<ReactCSSTransitionGroup transitionName="yolo" />,
|
||||
container
|
||||
);
|
||||
});
|
||||
|
||||
it('should work with a null child', function() {
|
||||
it('should work with a null child', () => {
|
||||
ReactDOM.render(
|
||||
<ReactCSSTransitionGroup transitionName="yolo">
|
||||
{[null]}
|
||||
@@ -180,7 +180,7 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should transition from one to null', function() {
|
||||
it('should transition from one to null', () => {
|
||||
var a = ReactDOM.render(
|
||||
<ReactCSSTransitionGroup transitionName="yolo">
|
||||
<span key="one" id="one" />
|
||||
@@ -200,7 +200,7 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
expect(ReactDOM.findDOMNode(a).childNodes[0].id).toBe('one');
|
||||
});
|
||||
|
||||
it('should transition from false to one', function() {
|
||||
it('should transition from false to one', () => {
|
||||
var a = ReactDOM.render(
|
||||
<ReactCSSTransitionGroup transitionName="yolo">
|
||||
{false}
|
||||
@@ -218,7 +218,7 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
expect(ReactDOM.findDOMNode(a).childNodes[0].id).toBe('one');
|
||||
});
|
||||
|
||||
it('should use transition-type specific names when they\'re provided', function() {
|
||||
it('should use transition-type specific names when they\'re provided', () => {
|
||||
var customTransitionNames = {
|
||||
enter: 'custom-entering',
|
||||
leave: 'custom-leaving',
|
||||
@@ -270,7 +270,7 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
expect(CSSCore.hasClass(leavingNode, 'custom-leaving')).toBe(true);
|
||||
});
|
||||
|
||||
it('should clear transition timeouts when unmounted', function() {
|
||||
it('should clear transition timeouts when unmounted', () => {
|
||||
class Component extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
@@ -292,7 +292,7 @@ describe('ReactCSSTransitionGroup', function() {
|
||||
jest.runAllTimers();
|
||||
});
|
||||
|
||||
it('should handle unmounted elements properly', function() {
|
||||
it('should handle unmounted elements properly', () => {
|
||||
class Child extends React.Component {
|
||||
render() {
|
||||
if (!this.props.show) {
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
var React;
|
||||
var ReactTransitionChildMapping;
|
||||
|
||||
describe('ReactTransitionChildMapping', function() {
|
||||
beforeEach(function() {
|
||||
describe('ReactTransitionChildMapping', () => {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactTransitionChildMapping = require('ReactTransitionChildMapping');
|
||||
});
|
||||
|
||||
it('should support getChildMapping', function() {
|
||||
it('should support getChildMapping', () => {
|
||||
var oneone = <div key="oneone" />;
|
||||
var onetwo = <div key="onetwo" />;
|
||||
var one = <div key="one">{oneone}{onetwo}</div>;
|
||||
@@ -34,7 +34,7 @@ describe('ReactTransitionChildMapping', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support mergeChildMappings for adding keys', function() {
|
||||
it('should support mergeChildMappings for adding keys', () => {
|
||||
var prev = {
|
||||
one: true,
|
||||
two: true,
|
||||
@@ -51,7 +51,7 @@ describe('ReactTransitionChildMapping', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support mergeChildMappings for removing keys', function() {
|
||||
it('should support mergeChildMappings for removing keys', () => {
|
||||
var prev = {
|
||||
one: true,
|
||||
two: true,
|
||||
@@ -68,7 +68,7 @@ describe('ReactTransitionChildMapping', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support mergeChildMappings for adding and removing', function() {
|
||||
it('should support mergeChildMappings for adding and removing', () => {
|
||||
var prev = {
|
||||
one: true,
|
||||
two: true,
|
||||
@@ -87,7 +87,7 @@ describe('ReactTransitionChildMapping', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should reconcile overlapping insertions and deletions', function() {
|
||||
it('should reconcile overlapping insertions and deletions', () => {
|
||||
var prev = {
|
||||
one: true,
|
||||
two: true,
|
||||
@@ -109,7 +109,7 @@ describe('ReactTransitionChildMapping', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support mergeChildMappings with undefined input', function() {
|
||||
it('should support mergeChildMappings with undefined input', () => {
|
||||
var prev = {
|
||||
one: true,
|
||||
two: true,
|
||||
|
||||
@@ -17,14 +17,14 @@ var ReactTransitionGroup;
|
||||
|
||||
// Most of the real functionality is covered in other unit tests, this just
|
||||
// makes sure we're wired up correctly.
|
||||
describe('ReactTransitionGroup', function() {
|
||||
describe('ReactTransitionGroup', () => {
|
||||
var container;
|
||||
|
||||
function normalizeCodeLocInfo(str) {
|
||||
return str.replace(/\(at .+?:\d+\)/g, '(at **)');
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
ReactTransitionGroup = require('ReactTransitionGroup');
|
||||
@@ -33,7 +33,7 @@ describe('ReactTransitionGroup', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should handle willEnter correctly', function() {
|
||||
it('should handle willEnter correctly', () => {
|
||||
var log = [];
|
||||
|
||||
class Child extends React.Component {
|
||||
@@ -103,7 +103,7 @@ describe('ReactTransitionGroup', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle enter/leave/enter/leave correctly', function() {
|
||||
it('should handle enter/leave/enter/leave correctly', () => {
|
||||
var log = [];
|
||||
var willEnterCb;
|
||||
|
||||
@@ -168,7 +168,7 @@ describe('ReactTransitionGroup', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle enter/leave/enter correctly', function() {
|
||||
it('should handle enter/leave/enter correctly', () => {
|
||||
var log = [];
|
||||
var willEnterCb;
|
||||
|
||||
@@ -231,7 +231,7 @@ describe('ReactTransitionGroup', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle entering/leaving several elements at once', function() {
|
||||
it('should handle entering/leaving several elements at once', () => {
|
||||
var log = [];
|
||||
|
||||
class Child extends React.Component {
|
||||
@@ -296,7 +296,7 @@ describe('ReactTransitionGroup', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should warn for duplicated keys with component stack info', function() {
|
||||
it('should warn for duplicated keys with component stack info', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
class Component extends React.Component {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var keyOf = require('keyOf');
|
||||
var invariant = require('invariant');
|
||||
var hasOwnProperty = {}.hasOwnProperty;
|
||||
|
||||
@@ -27,12 +26,12 @@ function shallowCopy(x) {
|
||||
}
|
||||
}
|
||||
|
||||
var COMMAND_PUSH = keyOf({$push: null});
|
||||
var COMMAND_UNSHIFT = keyOf({$unshift: null});
|
||||
var COMMAND_SPLICE = keyOf({$splice: null});
|
||||
var COMMAND_SET = keyOf({$set: null});
|
||||
var COMMAND_MERGE = keyOf({$merge: null});
|
||||
var COMMAND_APPLY = keyOf({$apply: null});
|
||||
var COMMAND_PUSH = '$push';
|
||||
var COMMAND_UNSHIFT = '$unshift';
|
||||
var COMMAND_SPLICE = '$splice';
|
||||
var COMMAND_SET = '$set';
|
||||
var COMMAND_MERGE = '$merge';
|
||||
var COMMAND_APPLY = '$apply';
|
||||
|
||||
var ALL_COMMANDS_LIST = [
|
||||
COMMAND_PUSH,
|
||||
|
||||
@@ -11,18 +11,18 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('ReactChildren', function() {
|
||||
describe('ReactChildren', () => {
|
||||
var ReactChildren;
|
||||
var React;
|
||||
var ReactFragment;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
ReactChildren = require('ReactChildren');
|
||||
React = require('React');
|
||||
ReactFragment = require('ReactFragment');
|
||||
});
|
||||
|
||||
it('should support identity for simple', function() {
|
||||
it('should support identity for simple', () => {
|
||||
var callback = jasmine.createSpy().and.callFake(function(kid, index) {
|
||||
return kid;
|
||||
});
|
||||
@@ -41,7 +41,7 @@ describe('ReactChildren', function() {
|
||||
expect(mappedChildren[0]).toEqual(<span key=".$simple" />);
|
||||
});
|
||||
|
||||
it('should treat single arrayless child as being in array', function() {
|
||||
it('should treat single arrayless child as being in array', () => {
|
||||
var callback = jasmine.createSpy().and.callFake(function(kid, index) {
|
||||
return kid;
|
||||
});
|
||||
@@ -56,7 +56,7 @@ describe('ReactChildren', function() {
|
||||
expect(mappedChildren[0]).toEqual(<span key=".0" />);
|
||||
});
|
||||
|
||||
it('should treat single child in array as expected', function() {
|
||||
it('should treat single child in array as expected', () => {
|
||||
var callback = jasmine.createSpy().and.callFake(function(kid, index) {
|
||||
return kid;
|
||||
});
|
||||
@@ -72,7 +72,7 @@ describe('ReactChildren', function() {
|
||||
|
||||
});
|
||||
|
||||
it('should pass key to returned component', function() {
|
||||
it('should pass key to returned component', () => {
|
||||
var mapFn = function(kid, index) {
|
||||
return <div>{kid}</div>;
|
||||
};
|
||||
@@ -88,7 +88,7 @@ describe('ReactChildren', function() {
|
||||
expect(mappedChildren[0].key).toBe('.$simple');
|
||||
});
|
||||
|
||||
it('should invoke callback with the right context', function() {
|
||||
it('should invoke callback with the right context', () => {
|
||||
var lastContext;
|
||||
var callback = function(kid, index) {
|
||||
lastContext = this;
|
||||
@@ -110,7 +110,7 @@ describe('ReactChildren', function() {
|
||||
expect(mappedChildren[0]).toBe(scopeTester);
|
||||
});
|
||||
|
||||
it('should be called for each child', function() {
|
||||
it('should be called for each child', () => {
|
||||
var zero = <div key="keyZero" />;
|
||||
var one = null;
|
||||
var two = <div key="keyTwo" />;
|
||||
@@ -172,7 +172,7 @@ describe('ReactChildren', function() {
|
||||
expect(mappedChildren[3]).toEqual(<div key=".$keyFour" />);
|
||||
});
|
||||
|
||||
it('should be called for each child in nested structure', function() {
|
||||
it('should be called for each child in nested structure', () => {
|
||||
var zero = <div key="keyZero" />;
|
||||
var one = null;
|
||||
var two = <div key="keyTwo" />;
|
||||
@@ -250,7 +250,7 @@ describe('ReactChildren', function() {
|
||||
expect(mappedChildren[3]).toEqual(<div key=".0:$keyFive/.$keyFiveInner" />);
|
||||
});
|
||||
|
||||
it('should retain key across two mappings', function() {
|
||||
it('should retain key across two mappings', () => {
|
||||
var zeroForceKey = <div key="keyZero" />;
|
||||
var oneForceKey = <div key="keyOne" />;
|
||||
|
||||
@@ -288,7 +288,7 @@ describe('ReactChildren', function() {
|
||||
|
||||
});
|
||||
|
||||
it('should not throw if key provided is a dupe with array key', function() {
|
||||
it('should not throw if key provided is a dupe with array key', () => {
|
||||
var zero = <div />;
|
||||
var one = <div key="0" />;
|
||||
|
||||
@@ -308,7 +308,7 @@ describe('ReactChildren', function() {
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('should use the same key for a cloned element', function() {
|
||||
it('should use the same key for a cloned element', () => {
|
||||
var instance = (
|
||||
<div>
|
||||
<div />
|
||||
@@ -328,7 +328,7 @@ describe('ReactChildren', function() {
|
||||
expect(mapped[0].key).toBe(mappedWithClone[0].key);
|
||||
});
|
||||
|
||||
it('should use the same key for a cloned element with key', function() {
|
||||
it('should use the same key for a cloned element with key', () => {
|
||||
var instance = (
|
||||
<div>
|
||||
<div key="unique" />
|
||||
@@ -348,24 +348,24 @@ describe('ReactChildren', function() {
|
||||
expect(mapped[0].key).toBe(mappedWithClone[0].key);
|
||||
});
|
||||
|
||||
it('should return 0 for null children', function() {
|
||||
it('should return 0 for null children', () => {
|
||||
var numberOfChildren = ReactChildren.count(null);
|
||||
expect(numberOfChildren).toBe(0);
|
||||
});
|
||||
|
||||
it('should return 0 for undefined children', function() {
|
||||
it('should return 0 for undefined children', () => {
|
||||
var numberOfChildren = ReactChildren.count(undefined);
|
||||
expect(numberOfChildren).toBe(0);
|
||||
});
|
||||
|
||||
it('should return 1 for single child', function() {
|
||||
it('should return 1 for single child', () => {
|
||||
var simpleKid = <span key="simple" />;
|
||||
var instance = <div>{simpleKid}</div>;
|
||||
var numberOfChildren = ReactChildren.count(instance.props.children);
|
||||
expect(numberOfChildren).toBe(1);
|
||||
});
|
||||
|
||||
it('should count the number of children in flat structure', function() {
|
||||
it('should count the number of children in flat structure', () => {
|
||||
var zero = <div key="keyZero" />;
|
||||
var one = null;
|
||||
var two = <div key="keyTwo" />;
|
||||
@@ -385,7 +385,7 @@ describe('ReactChildren', function() {
|
||||
expect(numberOfChildren).toBe(5);
|
||||
});
|
||||
|
||||
it('should count the number of children in nested structure', function() {
|
||||
it('should count the number of children in nested structure', () => {
|
||||
var zero = <div key="keyZero" />;
|
||||
var one = null;
|
||||
var two = <div key="keyTwo" />;
|
||||
@@ -414,7 +414,7 @@ describe('ReactChildren', function() {
|
||||
expect(numberOfChildren).toBe(5);
|
||||
});
|
||||
|
||||
it('should flatten children to an array', function() {
|
||||
it('should flatten children to an array', () => {
|
||||
expect(ReactChildren.toArray(undefined)).toEqual([]);
|
||||
expect(ReactChildren.toArray(null)).toEqual([]);
|
||||
|
||||
|
||||
@@ -11,14 +11,14 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('onlyChild', function() {
|
||||
describe('onlyChild', () => {
|
||||
|
||||
var React;
|
||||
var ReactFragment;
|
||||
var onlyChild;
|
||||
var WrapComponent;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactFragment = require('ReactFragment');
|
||||
onlyChild = require('onlyChild');
|
||||
@@ -33,7 +33,7 @@ describe('onlyChild', function() {
|
||||
};
|
||||
});
|
||||
|
||||
it('should fail when passed two children', function() {
|
||||
it('should fail when passed two children', () => {
|
||||
expect(function() {
|
||||
var instance =
|
||||
<WrapComponent>
|
||||
@@ -44,7 +44,7 @@ describe('onlyChild', function() {
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should fail when passed nully values', function() {
|
||||
it('should fail when passed nully values', () => {
|
||||
expect(function() {
|
||||
var instance =
|
||||
<WrapComponent>
|
||||
@@ -62,7 +62,7 @@ describe('onlyChild', function() {
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should fail when key/value objects', function() {
|
||||
it('should fail when key/value objects', () => {
|
||||
expect(function() {
|
||||
var instance =
|
||||
<WrapComponent>
|
||||
@@ -73,7 +73,7 @@ describe('onlyChild', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should not fail when passed interpolated single child', function() {
|
||||
it('should not fail when passed interpolated single child', () => {
|
||||
expect(function() {
|
||||
var instance =
|
||||
<WrapComponent>
|
||||
@@ -84,7 +84,7 @@ describe('onlyChild', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should return the only child', function() {
|
||||
it('should return the only child', () => {
|
||||
expect(function() {
|
||||
var instance =
|
||||
<WrapComponent>
|
||||
|
||||
@@ -11,19 +11,19 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('sliceChildren', function() {
|
||||
describe('sliceChildren', () => {
|
||||
|
||||
var React;
|
||||
|
||||
var sliceChildren;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
|
||||
sliceChildren = require('sliceChildren');
|
||||
});
|
||||
|
||||
it('should render the whole set if start zero is supplied', function() {
|
||||
it('should render the whole set if start zero is supplied', () => {
|
||||
var fullSet = [
|
||||
<div key="A" />,
|
||||
<div key="B" />,
|
||||
@@ -37,7 +37,7 @@ describe('sliceChildren', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should render the remaining set if no end index is supplied', function() {
|
||||
it('should render the remaining set if no end index is supplied', () => {
|
||||
var fullSet = [
|
||||
<div key="A" />,
|
||||
<div key="B" />,
|
||||
@@ -50,7 +50,7 @@ describe('sliceChildren', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should exclude everything at or after the end index', function() {
|
||||
it('should exclude everything at or after the end index', () => {
|
||||
var fullSet = [
|
||||
<div key="A" />,
|
||||
<div key="B" />,
|
||||
@@ -63,7 +63,7 @@ describe('sliceChildren', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should allow static children to be sliced', function() {
|
||||
it('should allow static children to be sliced', () => {
|
||||
var a = <a />;
|
||||
var b = <b />;
|
||||
var c = <i />;
|
||||
@@ -75,7 +75,7 @@ describe('sliceChildren', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should slice nested children', function() {
|
||||
it('should slice nested children', () => {
|
||||
var fullSet = [
|
||||
<div key="A" />,
|
||||
[
|
||||
|
||||
@@ -23,12 +23,12 @@ var ReactTestUtils;
|
||||
|
||||
var reactComponentExpect;
|
||||
|
||||
describe('ReactContextValidator', function() {
|
||||
describe('ReactContextValidator', () => {
|
||||
function normalizeCodeLocInfo(str) {
|
||||
return str.replace(/\(at .+?:\d+\)/g, '(at **)');
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
|
||||
React = require('React');
|
||||
@@ -40,7 +40,7 @@ describe('ReactContextValidator', function() {
|
||||
// TODO: This behavior creates a runtime dependency on propTypes. We should
|
||||
// ensure that this is not required for ES6 classes with Flow.
|
||||
|
||||
it('should filter out context not in contextTypes', function() {
|
||||
it('should filter out context not in contextTypes', () => {
|
||||
var Component = React.createClass({
|
||||
contextTypes: {
|
||||
foo: React.PropTypes.string,
|
||||
@@ -73,7 +73,7 @@ describe('ReactContextValidator', function() {
|
||||
reactComponentExpect(instance).expectRenderedChild().scalarContextEqual({foo: 'abc'});
|
||||
});
|
||||
|
||||
it('should filter context properly in callbacks', function() {
|
||||
it('should filter context properly in callbacks', () => {
|
||||
var actualComponentWillReceiveProps;
|
||||
var actualShouldComponentUpdate;
|
||||
var actualComponentWillUpdate;
|
||||
@@ -134,7 +134,7 @@ describe('ReactContextValidator', function() {
|
||||
expect(actualComponentDidUpdate).toEqual({foo: 'abc'});
|
||||
});
|
||||
|
||||
it('should check context types', function() {
|
||||
it('should check context types', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var Component = React.createClass({
|
||||
@@ -152,7 +152,8 @@ describe('ReactContextValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
|
||||
'Warning: Failed context type: ' +
|
||||
'Required context `foo` was not specified in `Component`.\n' +
|
||||
'The context `foo` is marked as required in `Component`, but its value ' +
|
||||
'is `undefined`.\n' +
|
||||
' in Component (at **)'
|
||||
);
|
||||
|
||||
@@ -207,7 +208,7 @@ describe('ReactContextValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should check child context types', function() {
|
||||
it('should check child context types', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var Component = React.createClass({
|
||||
@@ -229,7 +230,8 @@ describe('ReactContextValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
|
||||
'Warning: Failed childContext type: ' +
|
||||
'Required child context `foo` was not specified in `Component`.\n' +
|
||||
'The child context `foo` is marked as required in `Component`, but its ' +
|
||||
'value is `undefined`.\n' +
|
||||
' in Component (at **)'
|
||||
);
|
||||
|
||||
|
||||
@@ -13,42 +13,46 @@
|
||||
|
||||
var ReactComponent = require('ReactComponent');
|
||||
var ReactElement = require('ReactElement');
|
||||
var ReactPropTypeLocations = require('ReactPropTypeLocations');
|
||||
var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
|
||||
var ReactNoopUpdateQueue = require('ReactNoopUpdateQueue');
|
||||
|
||||
var emptyObject = require('emptyObject');
|
||||
var invariant = require('invariant');
|
||||
var keyMirror = require('keyMirror');
|
||||
var keyOf = require('keyOf');
|
||||
var warning = require('warning');
|
||||
|
||||
var MIXINS_KEY = keyOf({mixins: null});
|
||||
import type { ReactPropTypeLocations } from 'ReactPropTypeLocations';
|
||||
|
||||
var MIXINS_KEY = 'mixins';
|
||||
|
||||
// Helper function to allow the creation of anonymous functions which do not
|
||||
// have .name set to the name of the variable being assigned to.
|
||||
function identity(fn) {
|
||||
return fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Policies that describe methods in `ReactClassInterface`.
|
||||
*/
|
||||
var SpecPolicy = keyMirror({
|
||||
type SpecPolicy =
|
||||
/**
|
||||
* These methods may be defined only once by the class specification or mixin.
|
||||
*/
|
||||
DEFINE_ONCE: null,
|
||||
'DEFINE_ONCE' |
|
||||
/**
|
||||
* These methods may be defined by both the class specification and mixins.
|
||||
* Subsequent definitions will be chained. These methods must return void.
|
||||
*/
|
||||
DEFINE_MANY: null,
|
||||
'DEFINE_MANY' |
|
||||
/**
|
||||
* These methods are overriding the base class.
|
||||
*/
|
||||
OVERRIDE_BASE: null,
|
||||
'OVERRIDE_BASE' |
|
||||
/**
|
||||
* These methods are similar to DEFINE_MANY, except we assume they return
|
||||
* objects. We try to merge the keys of the return values of all the mixed in
|
||||
* functions. If there is a key conflict we throw.
|
||||
*/
|
||||
DEFINE_MANY_MERGED: null,
|
||||
});
|
||||
'DEFINE_MANY_MERGED';
|
||||
|
||||
|
||||
var injectedMixins = [];
|
||||
@@ -75,7 +79,7 @@ var injectedMixins = [];
|
||||
* @interface ReactClassInterface
|
||||
* @internal
|
||||
*/
|
||||
var ReactClassInterface = {
|
||||
var ReactClassInterface: {[key: string]: SpecPolicy} = {
|
||||
|
||||
/**
|
||||
* An array of Mixin objects to include when defining your component.
|
||||
@@ -83,7 +87,7 @@ var ReactClassInterface = {
|
||||
* @type {array}
|
||||
* @optional
|
||||
*/
|
||||
mixins: SpecPolicy.DEFINE_MANY,
|
||||
mixins: 'DEFINE_MANY',
|
||||
|
||||
/**
|
||||
* An object containing properties and methods that should be defined on
|
||||
@@ -92,7 +96,7 @@ var ReactClassInterface = {
|
||||
* @type {object}
|
||||
* @optional
|
||||
*/
|
||||
statics: SpecPolicy.DEFINE_MANY,
|
||||
statics: 'DEFINE_MANY',
|
||||
|
||||
/**
|
||||
* Definition of prop types for this component.
|
||||
@@ -100,7 +104,7 @@ var ReactClassInterface = {
|
||||
* @type {object}
|
||||
* @optional
|
||||
*/
|
||||
propTypes: SpecPolicy.DEFINE_MANY,
|
||||
propTypes: 'DEFINE_MANY',
|
||||
|
||||
/**
|
||||
* Definition of context types for this component.
|
||||
@@ -108,7 +112,7 @@ var ReactClassInterface = {
|
||||
* @type {object}
|
||||
* @optional
|
||||
*/
|
||||
contextTypes: SpecPolicy.DEFINE_MANY,
|
||||
contextTypes: 'DEFINE_MANY',
|
||||
|
||||
/**
|
||||
* Definition of context types this component sets for its children.
|
||||
@@ -116,7 +120,7 @@ var ReactClassInterface = {
|
||||
* @type {object}
|
||||
* @optional
|
||||
*/
|
||||
childContextTypes: SpecPolicy.DEFINE_MANY,
|
||||
childContextTypes: 'DEFINE_MANY',
|
||||
|
||||
// ==== Definition methods ====
|
||||
|
||||
@@ -130,7 +134,7 @@ var ReactClassInterface = {
|
||||
* @return {object}
|
||||
* @optional
|
||||
*/
|
||||
getDefaultProps: SpecPolicy.DEFINE_MANY_MERGED,
|
||||
getDefaultProps: 'DEFINE_MANY_MERGED',
|
||||
|
||||
/**
|
||||
* Invoked once before the component is mounted. The return value will be used
|
||||
@@ -146,13 +150,13 @@ var ReactClassInterface = {
|
||||
* @return {object}
|
||||
* @optional
|
||||
*/
|
||||
getInitialState: SpecPolicy.DEFINE_MANY_MERGED,
|
||||
getInitialState: 'DEFINE_MANY_MERGED',
|
||||
|
||||
/**
|
||||
* @return {object}
|
||||
* @optional
|
||||
*/
|
||||
getChildContext: SpecPolicy.DEFINE_MANY_MERGED,
|
||||
getChildContext: 'DEFINE_MANY_MERGED',
|
||||
|
||||
/**
|
||||
* Uses props from `this.props` and state from `this.state` to render the
|
||||
@@ -170,7 +174,7 @@ var ReactClassInterface = {
|
||||
* @nosideeffects
|
||||
* @required
|
||||
*/
|
||||
render: SpecPolicy.DEFINE_ONCE,
|
||||
render: 'DEFINE_ONCE',
|
||||
|
||||
|
||||
|
||||
@@ -183,7 +187,7 @@ var ReactClassInterface = {
|
||||
*
|
||||
* @optional
|
||||
*/
|
||||
componentWillMount: SpecPolicy.DEFINE_MANY,
|
||||
componentWillMount: 'DEFINE_MANY',
|
||||
|
||||
/**
|
||||
* Invoked when the component has been mounted and has a DOM representation.
|
||||
@@ -195,7 +199,7 @@ var ReactClassInterface = {
|
||||
* @param {DOMElement} rootNode DOM element representing the component.
|
||||
* @optional
|
||||
*/
|
||||
componentDidMount: SpecPolicy.DEFINE_MANY,
|
||||
componentDidMount: 'DEFINE_MANY',
|
||||
|
||||
/**
|
||||
* Invoked before the component receives new props.
|
||||
@@ -216,7 +220,7 @@ var ReactClassInterface = {
|
||||
* @param {object} nextProps
|
||||
* @optional
|
||||
*/
|
||||
componentWillReceiveProps: SpecPolicy.DEFINE_MANY,
|
||||
componentWillReceiveProps: 'DEFINE_MANY',
|
||||
|
||||
/**
|
||||
* Invoked while deciding if the component should be updated as a result of
|
||||
@@ -238,7 +242,7 @@ var ReactClassInterface = {
|
||||
* @return {boolean} True if the component should update.
|
||||
* @optional
|
||||
*/
|
||||
shouldComponentUpdate: SpecPolicy.DEFINE_ONCE,
|
||||
shouldComponentUpdate: 'DEFINE_ONCE',
|
||||
|
||||
/**
|
||||
* Invoked when the component is about to update due to a transition from
|
||||
@@ -255,7 +259,7 @@ var ReactClassInterface = {
|
||||
* @param {ReactReconcileTransaction} transaction
|
||||
* @optional
|
||||
*/
|
||||
componentWillUpdate: SpecPolicy.DEFINE_MANY,
|
||||
componentWillUpdate: 'DEFINE_MANY',
|
||||
|
||||
/**
|
||||
* Invoked when the component's DOM representation has been updated.
|
||||
@@ -269,7 +273,7 @@ var ReactClassInterface = {
|
||||
* @param {DOMElement} rootNode DOM element representing the component.
|
||||
* @optional
|
||||
*/
|
||||
componentDidUpdate: SpecPolicy.DEFINE_MANY,
|
||||
componentDidUpdate: 'DEFINE_MANY',
|
||||
|
||||
/**
|
||||
* Invoked when the component is about to be removed from its parent and have
|
||||
@@ -282,7 +286,7 @@ var ReactClassInterface = {
|
||||
*
|
||||
* @optional
|
||||
*/
|
||||
componentWillUnmount: SpecPolicy.DEFINE_MANY,
|
||||
componentWillUnmount: 'DEFINE_MANY',
|
||||
|
||||
|
||||
|
||||
@@ -298,7 +302,7 @@ var ReactClassInterface = {
|
||||
* @internal
|
||||
* @overridable
|
||||
*/
|
||||
updateComponent: SpecPolicy.OVERRIDE_BASE,
|
||||
updateComponent: 'OVERRIDE_BASE',
|
||||
|
||||
};
|
||||
|
||||
@@ -327,7 +331,7 @@ var RESERVED_SPEC_KEYS = {
|
||||
validateTypeDef(
|
||||
Constructor,
|
||||
childContextTypes,
|
||||
ReactPropTypeLocations.childContext
|
||||
'childContext'
|
||||
);
|
||||
}
|
||||
Constructor.childContextTypes = Object.assign(
|
||||
@@ -341,7 +345,7 @@ var RESERVED_SPEC_KEYS = {
|
||||
validateTypeDef(
|
||||
Constructor,
|
||||
contextTypes,
|
||||
ReactPropTypeLocations.context
|
||||
'context'
|
||||
);
|
||||
}
|
||||
Constructor.contextTypes = Object.assign(
|
||||
@@ -369,7 +373,7 @@ var RESERVED_SPEC_KEYS = {
|
||||
validateTypeDef(
|
||||
Constructor,
|
||||
propTypes,
|
||||
ReactPropTypeLocations.prop
|
||||
'prop'
|
||||
);
|
||||
}
|
||||
Constructor.propTypes = Object.assign(
|
||||
@@ -384,7 +388,11 @@ var RESERVED_SPEC_KEYS = {
|
||||
autobind: function() {}, // noop
|
||||
};
|
||||
|
||||
function validateTypeDef(Constructor, typeDef, location) {
|
||||
function validateTypeDef(
|
||||
Constructor,
|
||||
typeDef,
|
||||
location: ReactPropTypeLocations,
|
||||
) {
|
||||
for (var propName in typeDef) {
|
||||
if (typeDef.hasOwnProperty(propName)) {
|
||||
// use a warning instead of an invariant so components
|
||||
@@ -409,7 +417,7 @@ function validateMethodOverride(isAlreadyDefined, name) {
|
||||
// Disallow overriding of base class methods unless explicitly allowed.
|
||||
if (ReactClassMixin.hasOwnProperty(name)) {
|
||||
invariant(
|
||||
specPolicy === SpecPolicy.OVERRIDE_BASE,
|
||||
specPolicy === 'OVERRIDE_BASE',
|
||||
'ReactClassInterface: You are attempting to override ' +
|
||||
'`%s` from your class specification. Ensure that your method names ' +
|
||||
'do not overlap with React methods.',
|
||||
@@ -420,8 +428,8 @@ function validateMethodOverride(isAlreadyDefined, name) {
|
||||
// Disallow defining methods more than once unless explicitly allowed.
|
||||
if (isAlreadyDefined) {
|
||||
invariant(
|
||||
specPolicy === SpecPolicy.DEFINE_MANY ||
|
||||
specPolicy === SpecPolicy.DEFINE_MANY_MERGED,
|
||||
specPolicy === 'DEFINE_MANY' ||
|
||||
specPolicy === 'DEFINE_MANY_MERGED',
|
||||
'ReactClassInterface: You are attempting to define ' +
|
||||
'`%s` on your component more than once. This conflict may be due ' +
|
||||
'to a mixin.',
|
||||
@@ -516,8 +524,8 @@ function mixSpecIntoComponent(Constructor, spec) {
|
||||
// These cases should already be caught by validateMethodOverride.
|
||||
invariant(
|
||||
isReactClassMethod && (
|
||||
specPolicy === SpecPolicy.DEFINE_MANY_MERGED ||
|
||||
specPolicy === SpecPolicy.DEFINE_MANY
|
||||
specPolicy === 'DEFINE_MANY_MERGED' ||
|
||||
specPolicy === 'DEFINE_MANY'
|
||||
),
|
||||
'ReactClass: Unexpected spec policy %s for key %s ' +
|
||||
'when mixing in component specs.',
|
||||
@@ -527,9 +535,9 @@ function mixSpecIntoComponent(Constructor, spec) {
|
||||
|
||||
// For methods which are defined more than once, call the existing
|
||||
// methods before calling the new property, merging if appropriate.
|
||||
if (specPolicy === SpecPolicy.DEFINE_MANY_MERGED) {
|
||||
if (specPolicy === 'DEFINE_MANY_MERGED') {
|
||||
proto[name] = createMergedResultFunction(proto[name], property);
|
||||
} else if (specPolicy === SpecPolicy.DEFINE_MANY) {
|
||||
} else if (specPolicy === 'DEFINE_MANY') {
|
||||
proto[name] = createChainedFunction(proto[name], property);
|
||||
}
|
||||
} else {
|
||||
@@ -762,7 +770,10 @@ var ReactClass = {
|
||||
* @public
|
||||
*/
|
||||
createClass: function(spec) {
|
||||
var Constructor = function(props, context, updater) {
|
||||
// To keep our warnings more understandable, we'll use a little hack here to
|
||||
// ensure that Constructor.name !== 'Constructor'. This makes sure we don't
|
||||
// unnecessarily identify a class without displayName as 'Constructor'.
|
||||
var Constructor = identity(function(props, context, updater) {
|
||||
// This constructor gets overridden by mocks. The argument is used
|
||||
// by mocks to assert on what gets mounted.
|
||||
|
||||
@@ -806,7 +817,7 @@ var ReactClass = {
|
||||
);
|
||||
|
||||
this.state = initialState;
|
||||
};
|
||||
});
|
||||
Constructor.prototype = new ReactClassComponent();
|
||||
Constructor.prototype.constructor = Constructor;
|
||||
Constructor.prototype.__reactAutoBindPairs = [];
|
||||
|
||||
@@ -16,9 +16,9 @@ var ReactTestUtils = require('ReactTestUtils');
|
||||
var reactComponentExpect = require('reactComponentExpect');
|
||||
|
||||
// TODO: Test render and all stock methods.
|
||||
describe('autobinding', function() {
|
||||
describe('autobinding', () => {
|
||||
|
||||
it('Holds reference to instance', function() {
|
||||
it('Holds reference to instance', () => {
|
||||
|
||||
var mouseDidEnter = jest.fn();
|
||||
var mouseDidLeave = jest.fn();
|
||||
@@ -94,7 +94,7 @@ describe('autobinding', function() {
|
||||
expect(mouseDidLeave.mock.instances[1]).toBe(mountedInstance2);
|
||||
});
|
||||
|
||||
it('works with mixins', function() {
|
||||
it('works with mixins', () => {
|
||||
var mouseDidClick = jest.fn();
|
||||
|
||||
var TestMixin = {
|
||||
@@ -120,7 +120,7 @@ describe('autobinding', function() {
|
||||
expect(mouseDidClick.mock.instances[0]).toBe(mountedInstance1);
|
||||
});
|
||||
|
||||
it('warns if you try to bind to this', function() {
|
||||
it('warns if you try to bind to this', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var TestBindComponent = React.createClass({
|
||||
@@ -140,7 +140,7 @@ describe('autobinding', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('does not warn if you pass an auto-bound method to setState', function() {
|
||||
it('does not warn if you pass an auto-bound method to setState', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var TestBindComponent = React.createClass({
|
||||
|
||||
@@ -16,9 +16,9 @@ var ReactTestUtils = require('ReactTestUtils');
|
||||
var reactComponentExpect = require('reactComponentExpect');
|
||||
|
||||
// TODO: Test render and all stock methods.
|
||||
describe('autobind optout', function() {
|
||||
describe('autobind optout', () => {
|
||||
|
||||
it('should work with manual binding', function() {
|
||||
it('should work with manual binding', () => {
|
||||
|
||||
var mouseDidEnter = jest.fn();
|
||||
var mouseDidLeave = jest.fn();
|
||||
@@ -81,7 +81,7 @@ describe('autobind optout', function() {
|
||||
expect(mouseDidLeave.mock.instances[1]).toBe(mountedInstance2);
|
||||
});
|
||||
|
||||
it('should not hold reference to instance', function() {
|
||||
it('should not hold reference to instance', () => {
|
||||
var mouseDidClick = function() {
|
||||
void this.state.something;
|
||||
};
|
||||
@@ -137,7 +137,7 @@ describe('autobind optout', function() {
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('works with mixins that have not opted out of autobinding', function() {
|
||||
it('works with mixins that have not opted out of autobinding', () => {
|
||||
var mouseDidClick = jest.fn();
|
||||
|
||||
var TestMixin = {
|
||||
@@ -163,7 +163,7 @@ describe('autobind optout', function() {
|
||||
expect(mouseDidClick.mock.instances[0]).toBe(mountedInstance1);
|
||||
});
|
||||
|
||||
it('works with mixins that have opted out of autobinding', function() {
|
||||
it('works with mixins that have opted out of autobinding', () => {
|
||||
var mouseDidClick = jest.fn();
|
||||
|
||||
var TestMixin = {
|
||||
@@ -190,7 +190,7 @@ describe('autobind optout', function() {
|
||||
expect(mouseDidClick.mock.instances[0]).toBe(mountedInstance1);
|
||||
});
|
||||
|
||||
it('does not warn if you try to bind to this', function() {
|
||||
it('does not warn if you try to bind to this', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var TestBindComponent = React.createClass({
|
||||
@@ -206,7 +206,7 @@ describe('autobind optout', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not warn if you pass an manually bound method to setState', function() {
|
||||
it('does not warn if you pass an manually bound method to setState', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var TestBindComponent = React.createClass({
|
||||
|
||||
@@ -15,15 +15,15 @@ var React;
|
||||
var ReactDOM;
|
||||
var ReactTestUtils;
|
||||
|
||||
describe('ReactClass-spec', function() {
|
||||
describe('ReactClass-spec', () => {
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
ReactTestUtils = require('ReactTestUtils');
|
||||
});
|
||||
|
||||
it('should throw when `render` is not specified', function() {
|
||||
it('should throw when `render` is not specified', () => {
|
||||
expect(function() {
|
||||
React.createClass({});
|
||||
}).toThrowError(
|
||||
@@ -31,7 +31,7 @@ describe('ReactClass-spec', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should copy `displayName` onto the Constructor', function() {
|
||||
it('should copy `displayName` onto the Constructor', () => {
|
||||
var TestComponent = React.createClass({
|
||||
render: function() {
|
||||
return <div />;
|
||||
@@ -42,7 +42,7 @@ describe('ReactClass-spec', function() {
|
||||
.toBe('TestComponent');
|
||||
});
|
||||
|
||||
it('should copy prop types onto the Constructor', function() {
|
||||
it('should copy prop types onto the Constructor', () => {
|
||||
var propValidator = jest.fn();
|
||||
var TestComponent = React.createClass({
|
||||
propTypes: {
|
||||
@@ -58,7 +58,7 @@ describe('ReactClass-spec', function() {
|
||||
.toBe(propValidator);
|
||||
});
|
||||
|
||||
it('should warn on invalid prop types', function() {
|
||||
it('should warn on invalid prop types', () => {
|
||||
spyOn(console, 'error');
|
||||
React.createClass({
|
||||
displayName: 'Component',
|
||||
@@ -76,7 +76,7 @@ describe('ReactClass-spec', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn on invalid context types', function() {
|
||||
it('should warn on invalid context types', () => {
|
||||
spyOn(console, 'error');
|
||||
React.createClass({
|
||||
displayName: 'Component',
|
||||
@@ -94,7 +94,7 @@ describe('ReactClass-spec', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw on invalid child context types', function() {
|
||||
it('should throw on invalid child context types', () => {
|
||||
spyOn(console, 'error');
|
||||
React.createClass({
|
||||
displayName: 'Component',
|
||||
@@ -112,7 +112,7 @@ describe('ReactClass-spec', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when mispelling shouldComponentUpdate', function() {
|
||||
it('should warn when mispelling shouldComponentUpdate', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
React.createClass({
|
||||
@@ -147,7 +147,7 @@ describe('ReactClass-spec', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when mispelling componentWillReceiveProps', function() {
|
||||
it('should warn when mispelling componentWillReceiveProps', () => {
|
||||
spyOn(console, 'error');
|
||||
React.createClass({
|
||||
componentWillRecieveProps: function() {
|
||||
@@ -164,7 +164,7 @@ describe('ReactClass-spec', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if a reserved property is in statics', function() {
|
||||
it('should throw if a reserved property is in statics', () => {
|
||||
expect(function() {
|
||||
React.createClass({
|
||||
statics: {
|
||||
@@ -189,7 +189,7 @@ describe('ReactClass-spec', function() {
|
||||
|
||||
// TODO: Consider actually moving these to statics or drop this unit test.
|
||||
|
||||
xit('should warn when using deprecated non-static spec keys', function() {
|
||||
xit('should warn when using deprecated non-static spec keys', () => {
|
||||
spyOn(console, 'error');
|
||||
React.createClass({
|
||||
mixins: [{}],
|
||||
@@ -225,7 +225,7 @@ describe('ReactClass-spec', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should support statics', function() {
|
||||
it('should support statics', () => {
|
||||
var Component = React.createClass({
|
||||
statics: {
|
||||
abc: 'def',
|
||||
@@ -255,7 +255,7 @@ describe('ReactClass-spec', function() {
|
||||
expect(Component.pqr()).toBe(Component);
|
||||
});
|
||||
|
||||
it('should work with object getInitialState() return values', function() {
|
||||
it('should work with object getInitialState() return values', () => {
|
||||
var Component = React.createClass({
|
||||
getInitialState: function() {
|
||||
return {
|
||||
@@ -271,7 +271,7 @@ describe('ReactClass-spec', function() {
|
||||
expect(instance.state.occupation).toEqual('clown');
|
||||
});
|
||||
|
||||
it('renders based on context getInitialState', function() {
|
||||
it('renders based on context getInitialState', () => {
|
||||
var Foo = React.createClass({
|
||||
contextTypes: {
|
||||
className: React.PropTypes.string,
|
||||
@@ -301,7 +301,7 @@ describe('ReactClass-spec', function() {
|
||||
expect(container.firstChild.className).toBe('foo');
|
||||
});
|
||||
|
||||
it('should throw with non-object getInitialState() return values', function() {
|
||||
it('should throw with non-object getInitialState() return values', () => {
|
||||
[['an array'], 'a string', 1234].forEach(function(state) {
|
||||
var Component = React.createClass({
|
||||
getInitialState: function() {
|
||||
@@ -320,7 +320,7 @@ describe('ReactClass-spec', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with a null getInitialState() return value', function() {
|
||||
it('should work with a null getInitialState() return value', () => {
|
||||
var Component = React.createClass({
|
||||
getInitialState: function() {
|
||||
return null;
|
||||
@@ -334,7 +334,7 @@ describe('ReactClass-spec', function() {
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('should throw when using legacy factories', function() {
|
||||
it('should throw when using legacy factories', () => {
|
||||
spyOn(console, 'error');
|
||||
var Component = React.createClass({
|
||||
render() {
|
||||
|
||||
@@ -20,9 +20,9 @@ var TestComponentWithReverseSpec;
|
||||
var mixinPropValidator;
|
||||
var componentPropValidator;
|
||||
|
||||
describe('ReactClass-mixin', function() {
|
||||
describe('ReactClass-mixin', () => {
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactTestUtils = require('ReactTestUtils');
|
||||
mixinPropValidator = jest.fn();
|
||||
@@ -106,7 +106,7 @@ describe('ReactClass-mixin', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should support merging propTypes and statics', function() {
|
||||
it('should support merging propTypes and statics', () => {
|
||||
var listener = jest.fn();
|
||||
var instance = <TestComponent listener={listener} />;
|
||||
instance = ReactTestUtils.renderIntoDocument(instance);
|
||||
@@ -121,7 +121,7 @@ describe('ReactClass-mixin', function() {
|
||||
expect('staticComponent' in TestComponent).toBe(true);
|
||||
});
|
||||
|
||||
it('should support chaining delegate functions', function() {
|
||||
it('should support chaining delegate functions', () => {
|
||||
var listener = jest.fn();
|
||||
var instance = <TestComponent listener={listener} />;
|
||||
instance = ReactTestUtils.renderIntoDocument(instance);
|
||||
@@ -134,7 +134,7 @@ describe('ReactClass-mixin', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should chain functions regardless of spec property order', function() {
|
||||
it('should chain functions regardless of spec property order', () => {
|
||||
var listener = jest.fn();
|
||||
var instance = <TestComponentWithReverseSpec listener={listener} />;
|
||||
instance = ReactTestUtils.renderIntoDocument(instance);
|
||||
@@ -147,13 +147,13 @@ describe('ReactClass-mixin', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should validate prop types via mixins', function() {
|
||||
it('should validate prop types via mixins', () => {
|
||||
expect(TestComponent.propTypes).toBeDefined();
|
||||
expect(TestComponent.propTypes.value)
|
||||
.toBe(mixinPropValidator);
|
||||
});
|
||||
|
||||
it('should override mixin prop types with class prop types', function() {
|
||||
it('should override mixin prop types with class prop types', () => {
|
||||
// Sanity check...
|
||||
expect(componentPropValidator).not.toBe(mixinPropValidator);
|
||||
// Actually check...
|
||||
@@ -166,7 +166,7 @@ describe('ReactClass-mixin', function() {
|
||||
});
|
||||
|
||||
|
||||
it('should support mixins with getInitialState()', function() {
|
||||
it('should support mixins with getInitialState()', () => {
|
||||
var Mixin = {
|
||||
getInitialState: function() {
|
||||
return {mixin: true};
|
||||
@@ -187,7 +187,7 @@ describe('ReactClass-mixin', function() {
|
||||
expect(instance.state.mixin).toBe(true);
|
||||
});
|
||||
|
||||
it('should throw with conflicting getInitialState() methods', function() {
|
||||
it('should throw with conflicting getInitialState() methods', () => {
|
||||
var Mixin = {
|
||||
getInitialState: function() {
|
||||
return {x: true};
|
||||
@@ -213,7 +213,7 @@ describe('ReactClass-mixin', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not mutate objects returned by getInitialState()', function() {
|
||||
it('should not mutate objects returned by getInitialState()', () => {
|
||||
var Mixin = {
|
||||
getInitialState: function() {
|
||||
return Object.freeze({mixin: true});
|
||||
@@ -233,7 +233,7 @@ describe('ReactClass-mixin', function() {
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('should support statics in mixins', function() {
|
||||
it('should support statics in mixins', () => {
|
||||
var Mixin = {
|
||||
statics: {
|
||||
foo: 'bar',
|
||||
@@ -258,7 +258,7 @@ describe('ReactClass-mixin', function() {
|
||||
expect(Component.abc).toBe('def');
|
||||
});
|
||||
|
||||
it("should throw if mixins override each others' statics", function() {
|
||||
it("should throw if mixins override each others' statics", () => {
|
||||
expect(function() {
|
||||
var Mixin = {
|
||||
statics: {
|
||||
@@ -282,7 +282,7 @@ describe('ReactClass-mixin', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if mixins override functions in statics', function() {
|
||||
it('should throw if mixins override functions in statics', () => {
|
||||
expect(function() {
|
||||
var Mixin = {
|
||||
statics: {
|
||||
@@ -310,7 +310,7 @@ describe('ReactClass-mixin', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if the mixin is undefined', function() {
|
||||
it('should warn if the mixin is undefined', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
React.createClass({
|
||||
@@ -330,7 +330,7 @@ describe('ReactClass-mixin', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if the mixin is null', function() {
|
||||
it('should warn if the mixin is null', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
React.createClass({
|
||||
@@ -350,7 +350,7 @@ describe('ReactClass-mixin', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if an undefined mixin is included in another mixin', function() {
|
||||
it('should warn if an undefined mixin is included in another mixin', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var mixinA = {
|
||||
@@ -374,7 +374,7 @@ describe('ReactClass-mixin', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if a null mixin is included in another mixin', function() {
|
||||
it('should warn if a null mixin is included in another mixin', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var mixinA = {
|
||||
@@ -398,7 +398,7 @@ describe('ReactClass-mixin', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if the mixin is a React component', function() {
|
||||
it('should throw if the mixin is a React component', () => {
|
||||
expect(function() {
|
||||
React.createClass({
|
||||
mixins: [<div />],
|
||||
@@ -413,7 +413,7 @@ describe('ReactClass-mixin', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw if the mixin is a React component class', function() {
|
||||
it('should throw if the mixin is a React component class', () => {
|
||||
expect(function() {
|
||||
var Component = React.createClass({
|
||||
render: function() {
|
||||
@@ -434,7 +434,7 @@ describe('ReactClass-mixin', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should have bound the mixin methods to the component', function() {
|
||||
it('should have bound the mixin methods to the component', () => {
|
||||
var mixin = {
|
||||
mixinFunc: function() {
|
||||
return this;
|
||||
@@ -454,7 +454,7 @@ describe('ReactClass-mixin', function() {
|
||||
instance = ReactTestUtils.renderIntoDocument(instance);
|
||||
});
|
||||
|
||||
it('should include the mixin keys in even if their values are falsy', function() {
|
||||
it('should include the mixin keys in even if their values are falsy', () => {
|
||||
var mixin = {
|
||||
keyWithNullValue: null,
|
||||
randomCounter: 0,
|
||||
|
||||
@@ -7,10 +7,13 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactCurrentOwner
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type { ReactInstance } from 'ReactInstanceType';
|
||||
|
||||
/**
|
||||
* Keeps track of the current owner.
|
||||
*
|
||||
@@ -23,7 +26,7 @@ var ReactCurrentOwner = {
|
||||
* @internal
|
||||
* @type {ReactComponent}
|
||||
*/
|
||||
current: null,
|
||||
current: (null: null | ReactInstance),
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -17,11 +17,7 @@ var warning = require('warning');
|
||||
var canDefineProperty = require('canDefineProperty');
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
|
||||
// The Symbol used to tag the ReactElement type. If there is no native Symbol
|
||||
// nor polyfill, then a plain number is used for performance.
|
||||
var REACT_ELEMENT_TYPE =
|
||||
(typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) ||
|
||||
0xeac7;
|
||||
var REACT_ELEMENT_TYPE = require('ReactElementSymbol');
|
||||
|
||||
var RESERVED_PROPS = {
|
||||
key: true,
|
||||
@@ -139,7 +135,6 @@ var ReactElement = function(type, key, ref, self, source, owner, props) {
|
||||
// This can be replaced with a WeakMap once they are implemented in
|
||||
// commonly used development environments.
|
||||
element._store = {};
|
||||
var shadowChildren = Array.isArray(props.children) ? props.children.slice(0) : props.children;
|
||||
|
||||
// To make comparing ReactElements easier for testing purposes, we make
|
||||
// the validation flag non-enumerable (where possible, which should
|
||||
@@ -159,12 +154,6 @@ var ReactElement = function(type, key, ref, self, source, owner, props) {
|
||||
writable: false,
|
||||
value: self,
|
||||
});
|
||||
Object.defineProperty(element, '_shadowChildren', {
|
||||
configurable: false,
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
value: shadowChildren,
|
||||
});
|
||||
// Two elements created in two different places should be considered
|
||||
// equal for testing purposes and therefore we hide it from enumeration.
|
||||
Object.defineProperty(element, '_source', {
|
||||
@@ -176,7 +165,6 @@ var ReactElement = function(type, key, ref, self, source, owner, props) {
|
||||
} else {
|
||||
element._store.validated = false;
|
||||
element._self = self;
|
||||
element._shadowChildren = shadowChildren;
|
||||
element._source = source;
|
||||
}
|
||||
if (Object.freeze) {
|
||||
@@ -232,6 +220,11 @@ ReactElement.createElement = function(type, config, children) {
|
||||
for (var i = 0; i < childrenLength; i++) {
|
||||
childArray[i] = arguments[i + 2];
|
||||
}
|
||||
if (__DEV__) {
|
||||
if (Object.freeze) {
|
||||
Object.freeze(childArray);
|
||||
}
|
||||
}
|
||||
props.children = childArray;
|
||||
}
|
||||
|
||||
@@ -390,6 +383,4 @@ ReactElement.isValidElement = function(object) {
|
||||
);
|
||||
};
|
||||
|
||||
ReactElement.REACT_ELEMENT_TYPE = REACT_ELEMENT_TYPE;
|
||||
|
||||
module.exports = ReactElement;
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright 2016-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
* @providesModule ReactElementType
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import type { ReactInstance } from 'ReactInstanceType';
|
||||
|
||||
export type Source = {
|
||||
fileName: string,
|
||||
lineNumber: number,
|
||||
};
|
||||
|
||||
export type ReactElement = {
|
||||
$$typeof: any,
|
||||
type: any,
|
||||
key: any,
|
||||
ref: any,
|
||||
props: any,
|
||||
_owner: ReactInstance,
|
||||
|
||||
// __DEV__
|
||||
_store: {
|
||||
validated: boolean,
|
||||
},
|
||||
_self: ReactElement,
|
||||
_shadowChildren: any,
|
||||
_source: Source,
|
||||
};
|
||||
@@ -21,7 +21,6 @@
|
||||
var ReactCurrentOwner = require('ReactCurrentOwner');
|
||||
var ReactComponentTreeHook = require('ReactComponentTreeHook');
|
||||
var ReactElement = require('ReactElement');
|
||||
var ReactPropTypeLocations = require('ReactPropTypeLocations');
|
||||
|
||||
var checkReactTypeSpec = require('checkReactTypeSpec');
|
||||
|
||||
@@ -166,7 +165,7 @@ function validatePropTypes(element) {
|
||||
checkReactTypeSpec(
|
||||
componentClass.propTypes,
|
||||
element.props,
|
||||
ReactPropTypeLocations.prop,
|
||||
'prop',
|
||||
name,
|
||||
element,
|
||||
null
|
||||
|
||||
@@ -15,11 +15,11 @@ var React;
|
||||
var ReactDOM;
|
||||
var ReactTestUtils;
|
||||
|
||||
describe('ReactElement', function() {
|
||||
describe('ReactElement', () => {
|
||||
var ComponentClass;
|
||||
var originalSymbol;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
|
||||
// Delete the native Symbol if we have one to ensure we test the
|
||||
@@ -39,15 +39,15 @@ describe('ReactElement', function() {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(() => {
|
||||
global.Symbol = originalSymbol;
|
||||
});
|
||||
|
||||
it('uses the fallback value when in an environment without Symbol', function() {
|
||||
it('uses the fallback value when in an environment without Symbol', () => {
|
||||
expect(<div />.$$typeof).toBe(0xeac7);
|
||||
});
|
||||
|
||||
it('returns a complete element according to spec', function() {
|
||||
it('returns a complete element according to spec', () => {
|
||||
var element = React.createFactory(ComponentClass)();
|
||||
expect(element.type).toBe(ComponentClass);
|
||||
expect(element.key).toBe(null);
|
||||
@@ -57,7 +57,7 @@ describe('ReactElement', function() {
|
||||
expect(element.props).toEqual({});
|
||||
});
|
||||
|
||||
it('should warn when `key` is being accessed on createClass element', function() {
|
||||
it('should warn when `key` is being accessed on createClass element', () => {
|
||||
spyOn(console, 'error');
|
||||
var container = document.createElement('div');
|
||||
var Child = React.createClass({
|
||||
@@ -87,7 +87,7 @@ describe('ReactElement', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when `key` is being accessed on ES class element', function() {
|
||||
it('should warn when `key` is being accessed on ES class element', () => {
|
||||
spyOn(console, 'error');
|
||||
var container = document.createElement('div');
|
||||
class Child extends React.Component {
|
||||
@@ -117,7 +117,7 @@ describe('ReactElement', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when `key` is being accessed on a host element', function() {
|
||||
it('should warn when `key` is being accessed on a host element', () => {
|
||||
spyOn(console, 'error');
|
||||
var element = <div key="3" />;
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
@@ -131,7 +131,7 @@ describe('ReactElement', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when `ref` is being accessed', function() {
|
||||
it('should warn when `ref` is being accessed', () => {
|
||||
spyOn(console, 'error');
|
||||
var container = document.createElement('div');
|
||||
var Child = React.createClass({
|
||||
@@ -159,7 +159,7 @@ describe('ReactElement', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('allows a string to be passed as the type', function() {
|
||||
it('allows a string to be passed as the type', () => {
|
||||
var element = React.createFactory('div')();
|
||||
expect(element.type).toBe('div');
|
||||
expect(element.key).toBe(null);
|
||||
@@ -169,12 +169,12 @@ describe('ReactElement', function() {
|
||||
expect(element.props).toEqual({});
|
||||
});
|
||||
|
||||
it('returns an immutable element', function() {
|
||||
it('returns an immutable element', () => {
|
||||
var element = React.createFactory(ComponentClass)();
|
||||
expect(() => element.type = 'div').toThrow();
|
||||
});
|
||||
|
||||
it('does not reuse the original config object', function() {
|
||||
it('does not reuse the original config object', () => {
|
||||
var config = {foo: 1};
|
||||
var element = React.createFactory(ComponentClass)(config);
|
||||
expect(element.props.foo).toBe(1);
|
||||
@@ -182,13 +182,13 @@ describe('ReactElement', function() {
|
||||
expect(element.props.foo).toBe(1);
|
||||
});
|
||||
|
||||
it('does not fail if config has no prototype', function() {
|
||||
it('does not fail if config has no prototype', () => {
|
||||
var config = Object.create(null, {foo: {value: 1, enumerable: true}});
|
||||
var element = React.createFactory(ComponentClass)(config);
|
||||
expect(element.props.foo).toBe(1);
|
||||
});
|
||||
|
||||
it('extracts key and ref from the config', function() {
|
||||
it('extracts key and ref from the config', () => {
|
||||
var element = React.createFactory(ComponentClass)({
|
||||
key: '12',
|
||||
ref: '34',
|
||||
@@ -202,7 +202,7 @@ describe('ReactElement', function() {
|
||||
expect(element.props).toEqual({foo: '56'});
|
||||
});
|
||||
|
||||
it('extracts null key and ref', function() {
|
||||
it('extracts null key and ref', () => {
|
||||
var element = React.createFactory(ComponentClass)({
|
||||
key: null,
|
||||
ref: null,
|
||||
@@ -216,7 +216,7 @@ describe('ReactElement', function() {
|
||||
expect(element.props).toEqual({foo: '12'});
|
||||
});
|
||||
|
||||
it('ignores undefined key and ref', function() {
|
||||
it('ignores undefined key and ref', () => {
|
||||
var props = {
|
||||
foo: '56',
|
||||
key: undefined,
|
||||
@@ -231,14 +231,14 @@ describe('ReactElement', function() {
|
||||
expect(element.props).toEqual({foo: '56'});
|
||||
});
|
||||
|
||||
it('ignores key and ref warning getters', function() {
|
||||
it('ignores key and ref warning getters', () => {
|
||||
var elementA = React.createElement('div');
|
||||
var elementB = React.createElement('div', elementA.props);
|
||||
expect(elementB.key).toBe(null);
|
||||
expect(elementB.ref).toBe(null);
|
||||
});
|
||||
|
||||
it('coerces the key to a string', function() {
|
||||
it('coerces the key to a string', () => {
|
||||
var element = React.createFactory(ComponentClass)({
|
||||
key: 12,
|
||||
foo: '56',
|
||||
@@ -251,7 +251,7 @@ describe('ReactElement', function() {
|
||||
expect(element.props).toEqual({foo: '56'});
|
||||
});
|
||||
|
||||
it('preserves the owner on the element', function() {
|
||||
it('preserves the owner on the element', () => {
|
||||
var Component = React.createFactory(ComponentClass);
|
||||
var element;
|
||||
|
||||
@@ -269,7 +269,7 @@ describe('ReactElement', function() {
|
||||
expect(element._owner.getPublicInstance()).toBe(instance);
|
||||
});
|
||||
|
||||
it('merges an additional argument onto the children prop', function() {
|
||||
it('merges an additional argument onto the children prop', () => {
|
||||
spyOn(console, 'error');
|
||||
var a = 1;
|
||||
var element = React.createFactory(ComponentClass)({
|
||||
@@ -279,7 +279,7 @@ describe('ReactElement', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not override children if no rest args are provided', function() {
|
||||
it('does not override children if no rest args are provided', () => {
|
||||
spyOn(console, 'error');
|
||||
var element = React.createFactory(ComponentClass)({
|
||||
children: 'text',
|
||||
@@ -288,7 +288,7 @@ describe('ReactElement', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('overrides children if null is provided as an argument', function() {
|
||||
it('overrides children if null is provided as an argument', () => {
|
||||
spyOn(console, 'error');
|
||||
var element = React.createFactory(ComponentClass)({
|
||||
children: 'text',
|
||||
@@ -297,7 +297,7 @@ describe('ReactElement', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('merges rest arguments onto the children prop in an array', function() {
|
||||
it('merges rest arguments onto the children prop in an array', () => {
|
||||
spyOn(console, 'error');
|
||||
var a = 1;
|
||||
var b = 2;
|
||||
@@ -309,7 +309,7 @@ describe('ReactElement', function() {
|
||||
|
||||
// NOTE: We're explicitly not using JSX here. This is intended to test
|
||||
// classic JS without JSX.
|
||||
it('allows static methods to be called using the type property', function() {
|
||||
it('allows static methods to be called using the type property', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var StaticMethodComponentClass = React.createClass({
|
||||
@@ -333,7 +333,7 @@ describe('ReactElement', function() {
|
||||
|
||||
// NOTE: We're explicitly not using JSX here. This is intended to test
|
||||
// classic JS without JSX.
|
||||
it('identifies valid elements', function() {
|
||||
it('identifies valid elements', () => {
|
||||
var Component = React.createClass({
|
||||
render: function() {
|
||||
return React.createElement('div');
|
||||
@@ -357,7 +357,7 @@ describe('ReactElement', function() {
|
||||
expect(React.isValidElement(JSON.parse(jsonElement))).toBe(true);
|
||||
});
|
||||
|
||||
it('allows the use of PropTypes validators in statics', function() {
|
||||
it('allows the use of PropTypes validators in statics', () => {
|
||||
// TODO: This test was added to cover a special case where we proxied
|
||||
// methods. However, we don't do that any more so this test can probably
|
||||
// be removed. Leaving it in classic as a safety precaution.
|
||||
@@ -374,7 +374,7 @@ describe('ReactElement', function() {
|
||||
|
||||
// NOTE: We're explicitly not using JSX here. This is intended to test
|
||||
// classic JS without JSX.
|
||||
it('is indistinguishable from a plain object', function() {
|
||||
it('is indistinguishable from a plain object', () => {
|
||||
var element = React.createElement('div', {className: 'foo'});
|
||||
var object = {};
|
||||
expect(element.constructor).toBe(object.constructor);
|
||||
@@ -382,7 +382,7 @@ describe('ReactElement', function() {
|
||||
|
||||
// NOTE: We're explicitly not using JSX here. This is intended to test
|
||||
// classic JS without JSX.
|
||||
it('should use default prop value when removing a prop', function() {
|
||||
it('should use default prop value when removing a prop', () => {
|
||||
var Component = React.createClass({
|
||||
getDefaultProps: function() {
|
||||
return {fruit: 'persimmon'};
|
||||
@@ -405,7 +405,7 @@ describe('ReactElement', function() {
|
||||
|
||||
// NOTE: We're explicitly not using JSX here. This is intended to test
|
||||
// classic JS without JSX.
|
||||
it('should normalize props with default values', function() {
|
||||
it('should normalize props with default values', () => {
|
||||
var Component = React.createClass({
|
||||
getDefaultProps: function() {
|
||||
return {prop: 'testKey'};
|
||||
@@ -426,7 +426,7 @@ describe('ReactElement', function() {
|
||||
expect(inst2.props.prop).toBe(null);
|
||||
});
|
||||
|
||||
it('throws when changing a prop (in dev) after element creation', function() {
|
||||
it('throws when changing a prop (in dev) after element creation', () => {
|
||||
var Outer = React.createClass({
|
||||
render: function() {
|
||||
var el = <div className="moo" />;
|
||||
@@ -443,7 +443,7 @@ describe('ReactElement', function() {
|
||||
expect(ReactDOM.findDOMNode(outer).className).toBe('moo');
|
||||
});
|
||||
|
||||
it('throws when adding a prop (in dev) after element creation', function() {
|
||||
it('throws when adding a prop (in dev) after element creation', () => {
|
||||
var container = document.createElement('div');
|
||||
var Outer = React.createClass({
|
||||
getDefaultProps: () => ({sound: 'meow'}),
|
||||
@@ -464,7 +464,7 @@ describe('ReactElement', function() {
|
||||
expect(ReactDOM.findDOMNode(outer).className).toBe('');
|
||||
});
|
||||
|
||||
it('does not warn for NaN props', function() {
|
||||
it('does not warn for NaN props', () => {
|
||||
spyOn(console, 'error');
|
||||
var Test = React.createClass({
|
||||
render: function() {
|
||||
@@ -478,7 +478,7 @@ describe('ReactElement', function() {
|
||||
|
||||
// NOTE: We're explicitly not using JSX here. This is intended to test
|
||||
// classic JS without JSX.
|
||||
it('identifies elements, but not JSON, if Symbols are supported', function() {
|
||||
it('identifies elements, but not JSON, if Symbols are supported', () => {
|
||||
// Rudimentary polyfill
|
||||
// Once all jest engines support Symbols natively we can swap this to test
|
||||
// WITH native Symbols by default.
|
||||
@@ -523,10 +523,10 @@ describe('ReactElement', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('comparing jsx vs .createFactory() vs .createElement()', function() {
|
||||
describe('comparing jsx vs .createFactory() vs .createElement()', () => {
|
||||
var Child;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
@@ -535,9 +535,9 @@ describe('comparing jsx vs .createFactory() vs .createElement()', function() {
|
||||
});
|
||||
|
||||
|
||||
describe('when using jsx only', function() {
|
||||
describe('when using jsx only', () => {
|
||||
var Parent, instance;
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
Parent = React.createClass({
|
||||
render: function() {
|
||||
return (
|
||||
@@ -550,23 +550,23 @@ describe('comparing jsx vs .createFactory() vs .createElement()', function() {
|
||||
instance = ReactTestUtils.renderIntoDocument(<Parent/>);
|
||||
});
|
||||
|
||||
it('should scry children but cannot', function() {
|
||||
it('should scry children but cannot', () => {
|
||||
var children = ReactTestUtils.scryRenderedComponentsWithType(instance, Child);
|
||||
expect(children.length).toBe(1);
|
||||
});
|
||||
|
||||
it('does not maintain refs', function() {
|
||||
it('does not maintain refs', () => {
|
||||
expect(instance.refs.child).not.toBeUndefined();
|
||||
});
|
||||
|
||||
it('can capture Child instantiation calls', function() {
|
||||
it('can capture Child instantiation calls', () => {
|
||||
expect(Child.mock.calls[0][0]).toEqual({ foo: 'foo value', children: 'children value' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('when using parent that uses .createFactory()', function() {
|
||||
describe('when using parent that uses .createFactory()', () => {
|
||||
var factory, instance;
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
var childFactory = React.createFactory(Child);
|
||||
var Parent = React.createClass({
|
||||
render: function() {
|
||||
@@ -577,23 +577,23 @@ describe('comparing jsx vs .createFactory() vs .createElement()', function() {
|
||||
instance = ReactTestUtils.renderIntoDocument(factory());
|
||||
});
|
||||
|
||||
it('can properly scry children', function() {
|
||||
it('can properly scry children', () => {
|
||||
var children = ReactTestUtils.scryRenderedComponentsWithType(instance, Child);
|
||||
expect(children.length).toBe(1);
|
||||
});
|
||||
|
||||
it('does not maintain refs', function() {
|
||||
it('does not maintain refs', () => {
|
||||
expect(instance.refs.child).not.toBeUndefined();
|
||||
});
|
||||
|
||||
it('can capture Child instantiation calls', function() {
|
||||
it('can capture Child instantiation calls', () => {
|
||||
expect(Child.mock.calls[0][0]).toEqual({ foo: 'foo value', children: 'children value' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('when using parent that uses .createElement()', function() {
|
||||
describe('when using parent that uses .createElement()', () => {
|
||||
var factory, instance;
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
var Parent = React.createClass({
|
||||
render: function() {
|
||||
return React.DOM.div({}, React.createElement(Child, { ref: 'child', foo: 'foo value' }, 'children value'));
|
||||
@@ -603,16 +603,16 @@ describe('comparing jsx vs .createFactory() vs .createElement()', function() {
|
||||
instance = ReactTestUtils.renderIntoDocument(factory());
|
||||
});
|
||||
|
||||
it('should scry children but cannot', function() {
|
||||
it('should scry children but cannot', () => {
|
||||
var children = ReactTestUtils.scryRenderedComponentsWithType(instance, Child);
|
||||
expect(children.length).toBe(1);
|
||||
});
|
||||
|
||||
it('does not maintain refs', function() {
|
||||
it('does not maintain refs', () => {
|
||||
expect(instance.refs.child).not.toBeUndefined();
|
||||
});
|
||||
|
||||
it('can capture Child instantiation calls', function() {
|
||||
it('can capture Child instantiation calls', () => {
|
||||
expect(Child.mock.calls[0][0]).toEqual({ foo: 'foo value', children: 'children value' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,10 +15,10 @@ var React;
|
||||
var ReactDOM;
|
||||
var ReactTestUtils;
|
||||
|
||||
describe('ReactElementClone', function() {
|
||||
describe('ReactElementClone', () => {
|
||||
var ComponentClass;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
ReactTestUtils = require('ReactTestUtils');
|
||||
@@ -32,7 +32,7 @@ describe('ReactElementClone', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should clone a DOM component with new props', function() {
|
||||
it('should clone a DOM component with new props', () => {
|
||||
var Grandparent = React.createClass({
|
||||
render: function() {
|
||||
return <Parent child={<div className="child" />} />;
|
||||
@@ -51,7 +51,7 @@ describe('ReactElementClone', function() {
|
||||
expect(ReactDOM.findDOMNode(component).childNodes[0].className).toBe('xyz');
|
||||
});
|
||||
|
||||
it('should clone a composite component with new props', function() {
|
||||
it('should clone a composite component with new props', () => {
|
||||
var Child = React.createClass({
|
||||
render: function() {
|
||||
return <div className={this.props.className} />;
|
||||
@@ -75,12 +75,12 @@ describe('ReactElementClone', function() {
|
||||
expect(ReactDOM.findDOMNode(component).childNodes[0].className).toBe('xyz');
|
||||
});
|
||||
|
||||
it('does not fail if config has no prototype', function() {
|
||||
it('does not fail if config has no prototype', () => {
|
||||
var config = Object.create(null, {foo: {value: 1, enumerable: true}});
|
||||
React.cloneElement(<div />, config);
|
||||
});
|
||||
|
||||
it('should keep the original ref if it is not overridden', function() {
|
||||
it('should keep the original ref if it is not overridden', () => {
|
||||
var Grandparent = React.createClass({
|
||||
render: function() {
|
||||
return <Parent child={<div ref="yolo" />} />;
|
||||
@@ -101,7 +101,7 @@ describe('ReactElementClone', function() {
|
||||
expect(component.refs.yolo.tagName).toBe('DIV');
|
||||
});
|
||||
|
||||
it('should transfer the key property', function() {
|
||||
it('should transfer the key property', () => {
|
||||
var Component = React.createClass({
|
||||
render: function() {
|
||||
return null;
|
||||
@@ -111,7 +111,7 @@ describe('ReactElementClone', function() {
|
||||
expect(clone.key).toBe('xyz');
|
||||
});
|
||||
|
||||
it('should transfer children', function() {
|
||||
it('should transfer children', () => {
|
||||
var Component = React.createClass({
|
||||
render: function() {
|
||||
expect(this.props.children).toBe('xyz');
|
||||
@@ -124,7 +124,7 @@ describe('ReactElementClone', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should shallow clone children', function() {
|
||||
it('should shallow clone children', () => {
|
||||
var Component = React.createClass({
|
||||
render: function() {
|
||||
expect(this.props.children).toBe('xyz');
|
||||
@@ -137,7 +137,7 @@ describe('ReactElementClone', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should accept children as rest arguments', function() {
|
||||
it('should accept children as rest arguments', () => {
|
||||
var Component = React.createClass({
|
||||
render: function() {
|
||||
return null;
|
||||
@@ -157,7 +157,7 @@ describe('ReactElementClone', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should override children if undefined is provided as an argument', function() {
|
||||
it('should override children if undefined is provided as an argument', () => {
|
||||
var element = React.createElement(ComponentClass, {
|
||||
children: 'text',
|
||||
}, undefined);
|
||||
@@ -169,7 +169,7 @@ describe('ReactElementClone', function() {
|
||||
expect(element2.props.children).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should support keys and refs', function() {
|
||||
it('should support keys and refs', () => {
|
||||
var Parent = React.createClass({
|
||||
render: function() {
|
||||
var clone =
|
||||
@@ -190,7 +190,7 @@ describe('ReactElementClone', function() {
|
||||
expect(component.refs.parent.refs.xyz.tagName).toBe('SPAN');
|
||||
});
|
||||
|
||||
it('should steal the ref if a new ref is specified', function() {
|
||||
it('should steal the ref if a new ref is specified', () => {
|
||||
var Parent = React.createClass({
|
||||
render: function() {
|
||||
var clone = React.cloneElement(this.props.children, {ref: 'xyz'});
|
||||
@@ -209,7 +209,7 @@ describe('ReactElementClone', function() {
|
||||
expect(component.refs.parent.refs.xyz.tagName).toBe('SPAN');
|
||||
});
|
||||
|
||||
it('should overwrite props', function() {
|
||||
it('should overwrite props', () => {
|
||||
var Component = React.createClass({
|
||||
render: function() {
|
||||
expect(this.props.myprop).toBe('xyz');
|
||||
@@ -222,7 +222,7 @@ describe('ReactElementClone', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should normalize props with default values', function() {
|
||||
it('should normalize props with default values', () => {
|
||||
var Component = React.createClass({
|
||||
getDefaultProps: function() {
|
||||
return {prop: 'testKey'};
|
||||
@@ -245,7 +245,7 @@ describe('ReactElementClone', function() {
|
||||
expect(cloneInstance4.props.prop).toBe('newTestKey');
|
||||
});
|
||||
|
||||
it('warns for keys for arrays of elements in rest args', function() {
|
||||
it('warns for keys for arrays of elements in rest args', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
React.cloneElement(<div />, null, [<div />, <div />]);
|
||||
@@ -256,7 +256,7 @@ describe('ReactElementClone', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('does not warns for arrays of elements with keys', function() {
|
||||
it('does not warns for arrays of elements with keys', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
React.cloneElement(<div />, null, [<div key="#1" />, <div key="#2" />]);
|
||||
@@ -264,7 +264,7 @@ describe('ReactElementClone', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not warn when the element is directly in rest args', function() {
|
||||
it('does not warn when the element is directly in rest args', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
React.cloneElement(<div />, null, <div />, <div />);
|
||||
@@ -272,7 +272,7 @@ describe('ReactElementClone', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not warn when the array contains a non-element', function() {
|
||||
it('does not warn when the array contains a non-element', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
React.cloneElement(<div />, null, [{}, {}]);
|
||||
@@ -280,7 +280,7 @@ describe('ReactElementClone', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('should check declared prop types after clone', function() {
|
||||
it('should check declared prop types after clone', () => {
|
||||
spyOn(console, 'error');
|
||||
var Component = React.createClass({
|
||||
propTypes: {
|
||||
@@ -315,14 +315,14 @@ describe('ReactElementClone', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should ignore key and ref warning getters', function() {
|
||||
it('should ignore key and ref warning getters', () => {
|
||||
var elementA = React.createElement('div');
|
||||
var elementB = React.cloneElement(elementA, elementA.props);
|
||||
expect(elementB.key).toBe(null);
|
||||
expect(elementB.ref).toBe(null);
|
||||
});
|
||||
|
||||
it('should ignore undefined key and ref', function() {
|
||||
it('should ignore undefined key and ref', () => {
|
||||
var element = React.createFactory(ComponentClass)({
|
||||
key: '12',
|
||||
ref: '34',
|
||||
@@ -342,7 +342,7 @@ describe('ReactElementClone', function() {
|
||||
expect(clone.props).toEqual({foo: 'ef'});
|
||||
});
|
||||
|
||||
it('should extract null key and ref', function() {
|
||||
it('should extract null key and ref', () => {
|
||||
var element = React.createFactory(ComponentClass)({
|
||||
key: '12',
|
||||
ref: '34',
|
||||
|
||||
@@ -18,14 +18,14 @@ var React;
|
||||
var ReactDOM;
|
||||
var ReactTestUtils;
|
||||
|
||||
describe('ReactElementValidator', function() {
|
||||
describe('ReactElementValidator', () => {
|
||||
function normalizeCodeLocInfo(str) {
|
||||
return str.replace(/\(at .+?:\d+\)/g, '(at **)');
|
||||
}
|
||||
|
||||
var ComponentClass;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
|
||||
React = require('React');
|
||||
@@ -38,7 +38,7 @@ describe('ReactElementValidator', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('warns for keys for arrays of elements in rest args', function() {
|
||||
it('warns for keys for arrays of elements in rest args', () => {
|
||||
spyOn(console, 'error');
|
||||
var Component = React.createFactory(ComponentClass);
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('ReactElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('warns for keys for arrays of elements with owner info', function() {
|
||||
it('warns for keys for arrays of elements with owner info', () => {
|
||||
spyOn(console, 'error');
|
||||
var Component = React.createFactory(ComponentClass);
|
||||
|
||||
@@ -82,7 +82,7 @@ describe('ReactElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('warns for keys for arrays with no owner or parent info', function() {
|
||||
it('warns for keys for arrays with no owner or parent info', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var Anonymous = React.createClass({
|
||||
@@ -106,7 +106,7 @@ describe('ReactElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('warns for keys for arrays of elements with no owner info', function() {
|
||||
it('warns for keys for arrays of elements with no owner info', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var divs = [
|
||||
@@ -124,7 +124,7 @@ describe('ReactElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('warns for keys with component stack info', function() {
|
||||
it('warns for keys with component stack info', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var Component = React.createClass({
|
||||
@@ -159,7 +159,7 @@ describe('ReactElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('does not warn for keys when passing children down', function() {
|
||||
it('does not warn for keys when passing children down', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var Wrapper = React.createClass({
|
||||
@@ -183,7 +183,7 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('warns for keys for iterables of elements in rest args', function() {
|
||||
it('warns for keys for iterables of elements in rest args', () => {
|
||||
spyOn(console, 'error');
|
||||
var Component = React.createFactory(ComponentClass);
|
||||
|
||||
@@ -207,7 +207,7 @@ describe('ReactElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('does not warns for arrays of elements with keys', function() {
|
||||
it('does not warns for arrays of elements with keys', () => {
|
||||
spyOn(console, 'error');
|
||||
var Component = React.createFactory(ComponentClass);
|
||||
|
||||
@@ -216,7 +216,7 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not warns for iterable elements with keys', function() {
|
||||
it('does not warns for iterable elements with keys', () => {
|
||||
spyOn(console, 'error');
|
||||
var Component = React.createFactory(ComponentClass);
|
||||
|
||||
@@ -240,7 +240,7 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not warn when the element is directly in rest args', function() {
|
||||
it('does not warn when the element is directly in rest args', () => {
|
||||
spyOn(console, 'error');
|
||||
var Component = React.createFactory(ComponentClass);
|
||||
|
||||
@@ -249,7 +249,7 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not warn when the array contains a non-element', function() {
|
||||
it('does not warn when the array contains a non-element', () => {
|
||||
spyOn(console, 'error');
|
||||
var Component = React.createFactory(ComponentClass);
|
||||
|
||||
@@ -289,7 +289,7 @@ describe('ReactElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('gives a helpful error when passing null, undefined, boolean, or number', function() {
|
||||
it('gives a helpful error when passing null, undefined, boolean, or number', () => {
|
||||
spyOn(console, 'error');
|
||||
React.createElement(undefined);
|
||||
React.createElement(null);
|
||||
@@ -320,7 +320,7 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(4);
|
||||
});
|
||||
|
||||
it('includes the owner name when passing null, undefined, boolean, or number', function() {
|
||||
it('includes the owner name when passing null, undefined, boolean, or number', () => {
|
||||
spyOn(console, 'error');
|
||||
var ParentComp = React.createClass({
|
||||
render: function() {
|
||||
@@ -343,7 +343,7 @@ describe('ReactElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should check default prop values', function() {
|
||||
it('should check default prop values', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var Component = React.createClass({
|
||||
@@ -360,13 +360,13 @@ describe('ReactElementValidator', function() {
|
||||
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toBe(
|
||||
'Warning: Failed prop type: ' +
|
||||
'Required prop `prop` was not specified in `Component`.\n' +
|
||||
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
|
||||
'`Component`, but its value is `null`.\n' +
|
||||
' in Component'
|
||||
);
|
||||
});
|
||||
|
||||
it('should not check the default for explicit null', function() {
|
||||
it('should not check the default for explicit null', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var Component = React.createClass({
|
||||
@@ -385,13 +385,13 @@ describe('ReactElementValidator', function() {
|
||||
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
expect(console.error.calls.argsFor(0)[0]).toBe(
|
||||
'Warning: Failed prop type: ' +
|
||||
'Required prop `prop` was not specified in `Component`.\n' +
|
||||
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
|
||||
'`Component`, but its value is `null`.\n' +
|
||||
' in Component'
|
||||
);
|
||||
});
|
||||
|
||||
it('should check declared prop types', function() {
|
||||
it('should check declared prop types', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var Component = React.createClass({
|
||||
@@ -413,7 +413,8 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(2);
|
||||
expect(console.error.calls.argsFor(0)[0]).toBe(
|
||||
'Warning: Failed prop type: ' +
|
||||
'Required prop `prop` was not specified in `Component`.\n' +
|
||||
'The prop `prop` is marked as required in `Component`, but its value ' +
|
||||
'is `undefined`.\n' +
|
||||
' in Component'
|
||||
);
|
||||
|
||||
@@ -432,7 +433,7 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(2);
|
||||
});
|
||||
|
||||
it('should warn if a PropType creator is used as a PropType', function() {
|
||||
it('should warn if a PropType creator is used as a PropType', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var Component = React.createClass({
|
||||
@@ -458,7 +459,7 @@ describe('ReactElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when accessing .type on an element factory', function() {
|
||||
it('should warn when accessing .type on an element factory', () => {
|
||||
spyOn(console, 'error');
|
||||
var TestComponent = React.createClass({
|
||||
render: function() {
|
||||
@@ -477,7 +478,7 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
});
|
||||
|
||||
it('does not warn when using DOM node as children', function() {
|
||||
it('does not warn when using DOM node as children', () => {
|
||||
spyOn(console, 'error');
|
||||
var DOMContainer = React.createClass({
|
||||
render: function() {
|
||||
@@ -494,7 +495,7 @@ describe('ReactElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('should not enumerate enumerable numbers (#4776)', function() {
|
||||
it('should not enumerate enumerable numbers (#4776)', () => {
|
||||
/*eslint-disable no-extend-native */
|
||||
Number.prototype['@@iterator'] = function() {
|
||||
throw new Error('number iterator called');
|
||||
@@ -514,7 +515,7 @@ describe('ReactElementValidator', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('does not blow up with inlined children', function() {
|
||||
it('does not blow up with inlined children', () => {
|
||||
// We don't suggest this since it silences all sorts of warnings, but we
|
||||
// shouldn't blow up either.
|
||||
|
||||
@@ -530,7 +531,7 @@ describe('ReactElementValidator', function() {
|
||||
void <div>{[child]}</div>;
|
||||
});
|
||||
|
||||
it('does not blow up on key warning with undefined type', function() {
|
||||
it('does not blow up on key warning with undefined type', () => {
|
||||
spyOn(console, 'error');
|
||||
var Foo = undefined;
|
||||
void <Foo>{[<div />]}</Foo>;
|
||||
|
||||
@@ -145,9 +145,10 @@ function createChainableTypeChecker(validate) {
|
||||
false,
|
||||
'You are manually calling a React.PropTypes validation ' +
|
||||
'function for the `%s` prop on `%s`. This is deprecated ' +
|
||||
'and will not work in the next major version. You may be ' +
|
||||
'seeing this warning due to a third-party PropTypes library. ' +
|
||||
'See https://fb.me/react-warning-dont-call-proptypes for details.',
|
||||
'and will not work in production with the next major version. ' +
|
||||
'You may be seeing this warning due to a third-party PropTypes ' +
|
||||
'library. See https://fb.me/react-warning-dont-call-proptypes ' +
|
||||
'for details.',
|
||||
propFullName,
|
||||
componentName
|
||||
);
|
||||
@@ -158,9 +159,15 @@ function createChainableTypeChecker(validate) {
|
||||
if (props[propName] == null) {
|
||||
var locationName = ReactPropTypeLocationNames[location];
|
||||
if (isRequired) {
|
||||
if (props[propName] === null) {
|
||||
return new PropTypeError(
|
||||
`The ${locationName} \`${propFullName}\` is marked as required ` +
|
||||
`in \`${componentName}\`, but its value is \`null\`.`
|
||||
);
|
||||
}
|
||||
return new PropTypeError(
|
||||
`Required ${locationName} \`${propFullName}\` was not specified in ` +
|
||||
`\`${componentName}\`.`
|
||||
`The ${locationName} \`${propFullName}\` is marked as required in ` +
|
||||
`\`${componentName}\`, but its value is \`undefined\`.`
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -14,14 +14,11 @@
|
||||
var PropTypes;
|
||||
var React;
|
||||
var ReactFragment;
|
||||
var ReactPropTypeLocations;
|
||||
var ReactTestUtils;
|
||||
var ReactPropTypesSecret;
|
||||
|
||||
var Component;
|
||||
var MyComponent;
|
||||
var requiredMessage =
|
||||
'Required prop `testProp` was not specified in `testComponent`.';
|
||||
|
||||
function typeCheckFail(declaration, value, message) {
|
||||
var props = {testProp: value};
|
||||
@@ -29,7 +26,7 @@ function typeCheckFail(declaration, value, message) {
|
||||
props,
|
||||
'testProp',
|
||||
'testComponent',
|
||||
ReactPropTypeLocations.prop,
|
||||
'prop',
|
||||
null,
|
||||
ReactPropTypesSecret
|
||||
);
|
||||
@@ -37,13 +34,53 @@ function typeCheckFail(declaration, value, message) {
|
||||
expect(error.message).toBe(message);
|
||||
}
|
||||
|
||||
function typeCheckFailRequiredValues(declaration) {
|
||||
var specifiedButIsNullMsg = 'The prop `testProp` is marked as required in ' +
|
||||
'`testComponent`, but its value is `null`.';
|
||||
var unspecifiedMsg = 'The prop `testProp` is marked as required in ' +
|
||||
'`testComponent`, but its value is \`undefined\`.';
|
||||
var props1 = {testProp: null};
|
||||
var error1 = declaration(
|
||||
props1,
|
||||
'testProp',
|
||||
'testComponent',
|
||||
'prop',
|
||||
null,
|
||||
ReactPropTypesSecret
|
||||
);
|
||||
expect(error1 instanceof Error).toBe(true);
|
||||
expect(error1.message).toBe(specifiedButIsNullMsg);
|
||||
var props2 = {testProp: undefined};
|
||||
var error2 = declaration(
|
||||
props2,
|
||||
'testProp',
|
||||
'testComponent',
|
||||
'prop',
|
||||
null,
|
||||
ReactPropTypesSecret
|
||||
);
|
||||
expect(error2 instanceof Error).toBe(true);
|
||||
expect(error2.message).toBe(unspecifiedMsg);
|
||||
var props3 = {};
|
||||
var error3 = declaration(
|
||||
props3,
|
||||
'testProp',
|
||||
'testComponent',
|
||||
'prop',
|
||||
null,
|
||||
ReactPropTypesSecret
|
||||
);
|
||||
expect(error3 instanceof Error).toBe(true);
|
||||
expect(error3.message).toBe(unspecifiedMsg);
|
||||
}
|
||||
|
||||
function typeCheckPass(declaration, value) {
|
||||
var props = {testProp: value};
|
||||
var error = declaration(
|
||||
props,
|
||||
'testProp',
|
||||
'testComponent',
|
||||
ReactPropTypeLocations.prop,
|
||||
'prop',
|
||||
null,
|
||||
ReactPropTypesSecret
|
||||
);
|
||||
@@ -69,18 +106,17 @@ function expectWarningInDevelopment(declaration, value) {
|
||||
console.error.calls.reset();
|
||||
}
|
||||
|
||||
describe('ReactPropTypes', function() {
|
||||
beforeEach(function() {
|
||||
describe('ReactPropTypes', () => {
|
||||
beforeEach(() => {
|
||||
PropTypes = require('ReactPropTypes');
|
||||
React = require('React');
|
||||
ReactFragment = require('ReactFragment');
|
||||
ReactPropTypeLocations = require('ReactPropTypeLocations');
|
||||
ReactTestUtils = require('ReactTestUtils');
|
||||
ReactPropTypesSecret = require('ReactPropTypesSecret');
|
||||
});
|
||||
|
||||
describe('Primitive Types', function() {
|
||||
it('should warn for invalid strings', function() {
|
||||
describe('Primitive Types', () => {
|
||||
it('should warn for invalid strings', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.string,
|
||||
[],
|
||||
@@ -113,7 +149,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should fail date and regexp correctly', function() {
|
||||
it('should fail date and regexp correctly', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.string,
|
||||
new Date(),
|
||||
@@ -128,7 +164,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not warn for valid values', function() {
|
||||
it('should not warn for valid values', () => {
|
||||
typeCheckPass(PropTypes.array, []);
|
||||
typeCheckPass(PropTypes.bool, false);
|
||||
typeCheckPass(PropTypes.func, function() {});
|
||||
@@ -140,17 +176,16 @@ describe('ReactPropTypes', function() {
|
||||
typeCheckPass(PropTypes.symbol, Symbol());
|
||||
});
|
||||
|
||||
it('should be implicitly optional and not warn without values', function() {
|
||||
it('should be implicitly optional and not warn without values', () => {
|
||||
typeCheckPass(PropTypes.string, null);
|
||||
typeCheckPass(PropTypes.string, undefined);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(PropTypes.string.isRequired, null, requiredMessage);
|
||||
typeCheckFail(PropTypes.string.isRequired, undefined, requiredMessage);
|
||||
it('should warn for missing required values', () => {
|
||||
typeCheckFailRequiredValues(PropTypes.string.isRequired);
|
||||
});
|
||||
|
||||
it('should warn if called manually in development', function() {
|
||||
it('should warn if called manually in development', () => {
|
||||
spyOn(console, 'error');
|
||||
expectWarningInDevelopment(PropTypes.array, /please/);
|
||||
expectWarningInDevelopment(PropTypes.array, []);
|
||||
@@ -197,25 +232,24 @@ describe('ReactPropTypes', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Any type', function() {
|
||||
it('should should accept any value', function() {
|
||||
describe('Any type', () => {
|
||||
it('should should accept any value', () => {
|
||||
typeCheckPass(PropTypes.any, 0);
|
||||
typeCheckPass(PropTypes.any, 'str');
|
||||
typeCheckPass(PropTypes.any, []);
|
||||
typeCheckPass(PropTypes.any, Symbol());
|
||||
});
|
||||
|
||||
it('should be implicitly optional and not warn without values', function() {
|
||||
it('should be implicitly optional and not warn without values', () => {
|
||||
typeCheckPass(PropTypes.any, null);
|
||||
typeCheckPass(PropTypes.any, undefined);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(PropTypes.any.isRequired, null, requiredMessage);
|
||||
typeCheckFail(PropTypes.any.isRequired, undefined, requiredMessage);
|
||||
it('should warn for missing required values', () => {
|
||||
typeCheckFailRequiredValues(PropTypes.any.isRequired);
|
||||
});
|
||||
|
||||
it('should warn if called manually in development', function() {
|
||||
it('should warn if called manually in development', () => {
|
||||
spyOn(console, 'error');
|
||||
expectWarningInDevelopment(PropTypes.any, null);
|
||||
expectWarningInDevelopment(PropTypes.any.isRequired, null);
|
||||
@@ -223,8 +257,8 @@ describe('ReactPropTypes', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ArrayOf Type', function() {
|
||||
it('should fail for invalid argument', function() {
|
||||
describe('ArrayOf Type', () => {
|
||||
it('should fail for invalid argument', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.arrayOf({ foo: PropTypes.string }),
|
||||
{ foo: 'bar' },
|
||||
@@ -232,14 +266,14 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should support the arrayOf propTypes', function() {
|
||||
it('should support the arrayOf propTypes', () => {
|
||||
typeCheckPass(PropTypes.arrayOf(PropTypes.number), [1, 2, 3]);
|
||||
typeCheckPass(PropTypes.arrayOf(PropTypes.string), ['a', 'b', 'c']);
|
||||
typeCheckPass(PropTypes.arrayOf(PropTypes.oneOf(['a', 'b'])), ['a', 'b']);
|
||||
typeCheckPass(PropTypes.arrayOf(PropTypes.symbol), [Symbol(), Symbol()]);
|
||||
});
|
||||
|
||||
it('should support arrayOf with complex types', function() {
|
||||
it('should support arrayOf with complex types', () => {
|
||||
typeCheckPass(
|
||||
PropTypes.arrayOf(PropTypes.shape({a: PropTypes.number.isRequired})),
|
||||
[{a: 1}, {a: 2}]
|
||||
@@ -252,7 +286,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn with invalid items in the array', function() {
|
||||
it('should warn with invalid items in the array', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.arrayOf(PropTypes.number),
|
||||
[1, 2, 'b'],
|
||||
@@ -261,7 +295,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn with invalid complex types', function() {
|
||||
it('should warn with invalid complex types', () => {
|
||||
function Thing() {}
|
||||
var name = Thing.name || '<<anonymous>>';
|
||||
|
||||
@@ -273,7 +307,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when passed something other than an array', function() {
|
||||
it('should warn when passed something other than an array', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.arrayOf(PropTypes.number),
|
||||
{'0': 'maybe-array', length: 1},
|
||||
@@ -294,29 +328,22 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not warn when passing an empty array', function() {
|
||||
it('should not warn when passing an empty array', () => {
|
||||
typeCheckPass(PropTypes.arrayOf(PropTypes.number), []);
|
||||
});
|
||||
|
||||
it('should be implicitly optional and not warn without values', function() {
|
||||
it('should be implicitly optional and not warn without values', () => {
|
||||
typeCheckPass(PropTypes.arrayOf(PropTypes.number), null);
|
||||
typeCheckPass(PropTypes.arrayOf(PropTypes.number), undefined);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(
|
||||
PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||
null,
|
||||
requiredMessage
|
||||
);
|
||||
typeCheckFail(
|
||||
PropTypes.arrayOf(PropTypes.number).isRequired,
|
||||
undefined,
|
||||
requiredMessage
|
||||
it('should warn for missing required values', () => {
|
||||
typeCheckFailRequiredValues(
|
||||
PropTypes.arrayOf(PropTypes.number).isRequired
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if called manually in development', function() {
|
||||
it('should warn if called manually in development', () => {
|
||||
spyOn(console, 'error');
|
||||
expectWarningInDevelopment(
|
||||
PropTypes.arrayOf({ foo: PropTypes.string }),
|
||||
@@ -335,8 +362,8 @@ describe('ReactPropTypes', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Component Type', function() {
|
||||
beforeEach(function() {
|
||||
describe('Component Type', () => {
|
||||
beforeEach(() => {
|
||||
Component = class extends React.Component {
|
||||
static propTypes = {
|
||||
label: PropTypes.element.isRequired,
|
||||
@@ -397,17 +424,16 @@ describe('ReactPropTypes', function() {
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
});
|
||||
|
||||
it('should be implicitly optional and not warn without values', function() {
|
||||
it('should be implicitly optional and not warn without values', () => {
|
||||
typeCheckPass(PropTypes.element, null);
|
||||
typeCheckPass(PropTypes.element, undefined);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(PropTypes.element.isRequired, null, requiredMessage);
|
||||
typeCheckFail(PropTypes.element.isRequired, undefined, requiredMessage);
|
||||
it('should warn for missing required values', () => {
|
||||
typeCheckFailRequiredValues(PropTypes.element.isRequired);
|
||||
});
|
||||
|
||||
it('should warn if called manually in development', function() {
|
||||
it('should warn if called manually in development', () => {
|
||||
spyOn(console, 'error');
|
||||
expectWarningInDevelopment(PropTypes.element, [<div />, <div />]);
|
||||
expectWarningInDevelopment(PropTypes.element, <div />);
|
||||
@@ -420,8 +446,8 @@ describe('ReactPropTypes', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('Instance Types', function() {
|
||||
it('should warn for invalid instances', function() {
|
||||
describe('Instance Types', () => {
|
||||
it('should warn for invalid instances', () => {
|
||||
function Person() {}
|
||||
function Cat() {}
|
||||
var personName = Person.name || '<<anonymous>>';
|
||||
@@ -472,7 +498,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not warn for valid values', function() {
|
||||
it('should not warn for valid values', () => {
|
||||
function Person() {}
|
||||
function Engineer() {}
|
||||
Engineer.prototype = new Person();
|
||||
@@ -484,21 +510,16 @@ describe('ReactPropTypes', function() {
|
||||
typeCheckPass(PropTypes.instanceOf(RegExp), /please/);
|
||||
});
|
||||
|
||||
it('should be implicitly optional and not warn without values', function() {
|
||||
it('should be implicitly optional and not warn without values', () => {
|
||||
typeCheckPass(PropTypes.instanceOf(String), null);
|
||||
typeCheckPass(PropTypes.instanceOf(String), undefined);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(
|
||||
PropTypes.instanceOf(String).isRequired, null, requiredMessage
|
||||
);
|
||||
typeCheckFail(
|
||||
PropTypes.instanceOf(String).isRequired, undefined, requiredMessage
|
||||
);
|
||||
it('should warn for missing required values', () => {
|
||||
typeCheckFailRequiredValues(PropTypes.instanceOf(String).isRequired);
|
||||
});
|
||||
|
||||
it('should warn if called manually in development', function() {
|
||||
it('should warn if called manually in development', () => {
|
||||
spyOn(console, 'error');
|
||||
expectWarningInDevelopment(PropTypes.instanceOf(Date), {});
|
||||
expectWarningInDevelopment(PropTypes.instanceOf(Date), new Date());
|
||||
@@ -508,8 +529,8 @@ describe('ReactPropTypes', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('React Component Types', function() {
|
||||
beforeEach(function() {
|
||||
describe('React Component Types', () => {
|
||||
beforeEach(() => {
|
||||
MyComponent = class extends React.Component {
|
||||
render() {
|
||||
return <div />;
|
||||
@@ -517,7 +538,7 @@ describe('ReactPropTypes', function() {
|
||||
};
|
||||
});
|
||||
|
||||
it('should warn for invalid values', function() {
|
||||
it('should warn for invalid values', () => {
|
||||
var failMessage = 'Invalid prop `testProp` supplied to ' +
|
||||
'`testComponent`, expected a ReactNode.';
|
||||
typeCheckFail(PropTypes.node, true, failMessage);
|
||||
@@ -526,7 +547,7 @@ describe('ReactPropTypes', function() {
|
||||
typeCheckFail(PropTypes.node, {key: <div />}, failMessage);
|
||||
});
|
||||
|
||||
it('should not warn for valid values', function() {
|
||||
it('should not warn for valid values', () => {
|
||||
spyOn(console, 'error');
|
||||
typeCheckPass(PropTypes.node, <div />);
|
||||
typeCheckPass(PropTypes.node, false);
|
||||
@@ -559,7 +580,7 @@ describe('ReactPropTypes', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('should not warn for iterables', function() {
|
||||
it('should not warn for iterables', () => {
|
||||
var iterable = {
|
||||
'@@iterator': function() {
|
||||
var i = 0;
|
||||
@@ -575,7 +596,7 @@ describe('ReactPropTypes', function() {
|
||||
typeCheckPass(PropTypes.node, iterable);
|
||||
});
|
||||
|
||||
it('should not warn for entry iterables', function() {
|
||||
it('should not warn for entry iterables', () => {
|
||||
var iterable = {
|
||||
'@@iterator': function() {
|
||||
var i = 0;
|
||||
@@ -592,29 +613,20 @@ describe('ReactPropTypes', function() {
|
||||
typeCheckPass(PropTypes.node, iterable);
|
||||
});
|
||||
|
||||
it('should not warn for null/undefined if not required', function() {
|
||||
it('should not warn for null/undefined if not required', () => {
|
||||
typeCheckPass(PropTypes.node, null);
|
||||
typeCheckPass(PropTypes.node, undefined);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(
|
||||
PropTypes.node.isRequired,
|
||||
null,
|
||||
'Required prop `testProp` was not specified in `testComponent`.'
|
||||
);
|
||||
typeCheckFail(
|
||||
PropTypes.node.isRequired,
|
||||
undefined,
|
||||
'Required prop `testProp` was not specified in `testComponent`.'
|
||||
);
|
||||
it('should warn for missing required values', () => {
|
||||
typeCheckFailRequiredValues(PropTypes.node.isRequired);
|
||||
});
|
||||
|
||||
it('should accept empty array for required props', function() {
|
||||
it('should accept empty array for required props', () => {
|
||||
typeCheckPass(PropTypes.node.isRequired, []);
|
||||
});
|
||||
|
||||
it('should warn if called manually in development', function() {
|
||||
it('should warn if called manually in development', () => {
|
||||
spyOn(console, 'error');
|
||||
expectWarningInDevelopment(PropTypes.node, 'node');
|
||||
expectWarningInDevelopment(PropTypes.node, {});
|
||||
@@ -625,8 +637,8 @@ describe('ReactPropTypes', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('ObjectOf Type', function() {
|
||||
it('should fail for invalid argument', function() {
|
||||
describe('ObjectOf Type', () => {
|
||||
it('should fail for invalid argument', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.objectOf({ foo: PropTypes.string }),
|
||||
{ foo: 'bar' },
|
||||
@@ -634,7 +646,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should support the objectOf propTypes', function() {
|
||||
it('should support the objectOf propTypes', () => {
|
||||
typeCheckPass(PropTypes.objectOf(PropTypes.number), {a: 1, b: 2, c: 3});
|
||||
typeCheckPass(
|
||||
PropTypes.objectOf(PropTypes.string),
|
||||
@@ -650,7 +662,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should support objectOf with complex types', function() {
|
||||
it('should support objectOf with complex types', () => {
|
||||
typeCheckPass(
|
||||
PropTypes.objectOf(PropTypes.shape({a: PropTypes.number.isRequired})),
|
||||
{a: {a: 1}, b: {a: 2}}
|
||||
@@ -663,7 +675,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn with invalid items in the object', function() {
|
||||
it('should warn with invalid items in the object', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.objectOf(PropTypes.number),
|
||||
{a: 1, b: 2, c: 'b'},
|
||||
@@ -672,7 +684,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn with invalid complex types', function() {
|
||||
it('should warn with invalid complex types', () => {
|
||||
function Thing() {}
|
||||
var name = Thing.name || '<<anonymous>>';
|
||||
|
||||
@@ -684,7 +696,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when passed something other than an object', function() {
|
||||
it('should warn when passed something other than an object', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.objectOf(PropTypes.number),
|
||||
[1, 2],
|
||||
@@ -711,29 +723,22 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not warn when passing an empty object', function() {
|
||||
it('should not warn when passing an empty object', () => {
|
||||
typeCheckPass(PropTypes.objectOf(PropTypes.number), {});
|
||||
});
|
||||
|
||||
it('should be implicitly optional and not warn without values', function() {
|
||||
it('should be implicitly optional and not warn without values', () => {
|
||||
typeCheckPass(PropTypes.objectOf(PropTypes.number), null);
|
||||
typeCheckPass(PropTypes.objectOf(PropTypes.number), undefined);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(
|
||||
PropTypes.objectOf(PropTypes.number).isRequired,
|
||||
null,
|
||||
requiredMessage
|
||||
);
|
||||
typeCheckFail(
|
||||
PropTypes.objectOf(PropTypes.number).isRequired,
|
||||
undefined,
|
||||
requiredMessage
|
||||
it('should warn for missing required values', () => {
|
||||
typeCheckFailRequiredValues(
|
||||
PropTypes.objectOf(PropTypes.number).isRequired
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if called manually in development', function() {
|
||||
it('should warn if called manually in development', () => {
|
||||
spyOn(console, 'error');
|
||||
expectWarningInDevelopment(
|
||||
PropTypes.objectOf({ foo: PropTypes.string }),
|
||||
@@ -749,8 +754,8 @@ describe('ReactPropTypes', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('OneOf Types', function() {
|
||||
it('should warn but not error for invalid argument', function() {
|
||||
describe('OneOf Types', () => {
|
||||
it('should warn but not error for invalid argument', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
PropTypes.oneOf('red', 'blue');
|
||||
@@ -762,7 +767,7 @@ describe('ReactPropTypes', function() {
|
||||
typeCheckPass(PropTypes.oneOf('red', 'blue'), 'red');
|
||||
});
|
||||
|
||||
it('should warn for invalid values', function() {
|
||||
it('should warn for invalid values', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.oneOf(['red', 'blue']),
|
||||
true,
|
||||
@@ -789,31 +794,22 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not warn for valid values', function() {
|
||||
it('should not warn for valid values', () => {
|
||||
typeCheckPass(PropTypes.oneOf(['red', 'blue']), 'red');
|
||||
typeCheckPass(PropTypes.oneOf(['red', 'blue']), 'blue');
|
||||
typeCheckPass(PropTypes.oneOf(['red', 'blue', NaN]), NaN);
|
||||
});
|
||||
|
||||
it('should be implicitly optional and not warn without values', function() {
|
||||
it('should be implicitly optional and not warn without values', () => {
|
||||
typeCheckPass(PropTypes.oneOf(['red', 'blue']), null);
|
||||
typeCheckPass(PropTypes.oneOf(['red', 'blue']), undefined);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(
|
||||
PropTypes.oneOf(['red', 'blue']).isRequired,
|
||||
null,
|
||||
requiredMessage
|
||||
);
|
||||
typeCheckFail(
|
||||
PropTypes.oneOf(['red', 'blue']).isRequired,
|
||||
undefined,
|
||||
requiredMessage
|
||||
);
|
||||
it('should warn for missing required values', () => {
|
||||
typeCheckFailRequiredValues(PropTypes.oneOf(['red', 'blue']).isRequired);
|
||||
});
|
||||
|
||||
it('should warn if called manually in development', function() {
|
||||
it('should warn if called manually in development', () => {
|
||||
spyOn(console, 'error');
|
||||
expectWarningInDevelopment(PropTypes.oneOf(['red', 'blue']), true);
|
||||
expectWarningInDevelopment(PropTypes.oneOf(['red', 'blue']), null);
|
||||
@@ -821,8 +817,8 @@ describe('ReactPropTypes', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Union Types', function() {
|
||||
it('should warn but not error for invalid argument', function() {
|
||||
describe('Union Types', () => {
|
||||
it('should warn but not error for invalid argument', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
PropTypes.oneOfType(PropTypes.string, PropTypes.number);
|
||||
@@ -834,7 +830,7 @@ describe('ReactPropTypes', function() {
|
||||
typeCheckPass(PropTypes.oneOf(PropTypes.string, PropTypes.number), []);
|
||||
});
|
||||
|
||||
it('should warn if none of the types are valid', function() {
|
||||
it('should warn if none of the types are valid', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
[],
|
||||
@@ -852,7 +848,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not warn if one of the types are valid', function() {
|
||||
it('should not warn if one of the types are valid', () => {
|
||||
var checker = PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.number,
|
||||
@@ -869,7 +865,7 @@ describe('ReactPropTypes', function() {
|
||||
typeCheckPass(checker, {b: 1});
|
||||
});
|
||||
|
||||
it('should be implicitly optional and not warn without values', function() {
|
||||
it('should be implicitly optional and not warn without values', () => {
|
||||
typeCheckPass(
|
||||
PropTypes.oneOfType([PropTypes.string, PropTypes.number]), null
|
||||
);
|
||||
@@ -878,20 +874,13 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(
|
||||
PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
||||
null,
|
||||
requiredMessage
|
||||
);
|
||||
typeCheckFail(
|
||||
PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
||||
undefined,
|
||||
requiredMessage
|
||||
it('should warn for missing required values', () => {
|
||||
typeCheckFailRequiredValues(
|
||||
PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if called manually in development', function() {
|
||||
it('should warn if called manually in development', () => {
|
||||
spyOn(console, 'error');
|
||||
expectWarningInDevelopment(
|
||||
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
@@ -909,8 +898,8 @@ describe('ReactPropTypes', function() {
|
||||
|
||||
});
|
||||
|
||||
describe('Shape Types', function() {
|
||||
it('should warn for non objects', function() {
|
||||
describe('Shape Types', () => {
|
||||
it('should warn for non objects', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.shape({}),
|
||||
'some string',
|
||||
@@ -925,44 +914,46 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not warn for empty values', function() {
|
||||
it('should not warn for empty values', () => {
|
||||
typeCheckPass(PropTypes.shape({}), undefined);
|
||||
typeCheckPass(PropTypes.shape({}), null);
|
||||
typeCheckPass(PropTypes.shape({}), {});
|
||||
});
|
||||
|
||||
it('should not warn for an empty object', function() {
|
||||
it('should not warn for an empty object', () => {
|
||||
typeCheckPass(PropTypes.shape({}).isRequired, {});
|
||||
});
|
||||
|
||||
it('should not warn for non specified types', function() {
|
||||
it('should not warn for non specified types', () => {
|
||||
typeCheckPass(PropTypes.shape({}), {key: 1});
|
||||
});
|
||||
|
||||
it('should not warn for valid types', function() {
|
||||
it('should not warn for valid types', () => {
|
||||
typeCheckPass(PropTypes.shape({key: PropTypes.number}), {key: 1});
|
||||
});
|
||||
|
||||
it('should warn for required valid types', function() {
|
||||
it('should warn for required valid types', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.shape({key: PropTypes.number.isRequired}),
|
||||
{},
|
||||
'Required prop `testProp.key` was not specified in `testComponent`.'
|
||||
'The prop `testProp.key` is marked as required in `testComponent`, ' +
|
||||
'but its value is `undefined`.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn for the first required type', function() {
|
||||
it('should warn for the first required type', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.shape({
|
||||
key: PropTypes.number.isRequired,
|
||||
secondKey: PropTypes.number.isRequired,
|
||||
}),
|
||||
{},
|
||||
'Required prop `testProp.key` was not specified in `testComponent`.'
|
||||
'The prop `testProp.key` is marked as required in `testComponent`, ' +
|
||||
'but its value is `undefined`.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn for invalid key types', function() {
|
||||
it('should warn for invalid key types', () => {
|
||||
typeCheckFail(PropTypes.shape({key: PropTypes.number}),
|
||||
{key: 'abc'},
|
||||
'Invalid prop `testProp.key` of type `string` supplied to `testComponent`, ' +
|
||||
@@ -970,7 +961,7 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should be implicitly optional and not warn without values', function() {
|
||||
it('should be implicitly optional and not warn without values', () => {
|
||||
typeCheckPass(
|
||||
PropTypes.shape(PropTypes.shape({key: PropTypes.number})), null
|
||||
);
|
||||
@@ -979,20 +970,13 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn for missing required values', function() {
|
||||
typeCheckFail(
|
||||
PropTypes.shape({key: PropTypes.number}).isRequired,
|
||||
null,
|
||||
requiredMessage
|
||||
);
|
||||
typeCheckFail(
|
||||
PropTypes.shape({key: PropTypes.number}).isRequired,
|
||||
undefined,
|
||||
requiredMessage
|
||||
it('should warn for missing required values', () => {
|
||||
typeCheckFailRequiredValues(
|
||||
PropTypes.shape({key: PropTypes.number}).isRequired
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if called manually in development', function() {
|
||||
it('should warn if called manually in development', () => {
|
||||
spyOn(console, 'error');
|
||||
expectWarningInDevelopment(PropTypes.shape({}), 'some string');
|
||||
expectWarningInDevelopment(PropTypes.shape({ foo: PropTypes.number }), { foo: 42 });
|
||||
@@ -1008,8 +992,8 @@ describe('ReactPropTypes', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Symbol Type', function() {
|
||||
it('should warn for non-symbol', function() {
|
||||
describe('Symbol Type', () => {
|
||||
it('should warn for non-symbol', () => {
|
||||
typeCheckFail(
|
||||
PropTypes.symbol,
|
||||
'hello',
|
||||
@@ -1032,18 +1016,18 @@ describe('ReactPropTypes', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should not warn for a polyfilled Symbol', function() {
|
||||
it('should not warn for a polyfilled Symbol', () => {
|
||||
var CoreSymbol = require('core-js/library/es6/symbol');
|
||||
typeCheckPass(PropTypes.symbol, CoreSymbol('core-js'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Custom validator', function() {
|
||||
beforeEach(function() {
|
||||
describe('Custom validator', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
});
|
||||
|
||||
it('should have been called with the right params', function() {
|
||||
it('should have been called with the right params', () => {
|
||||
var spy = jasmine.createSpy();
|
||||
Component = class extends React.Component {
|
||||
static propTypes = {num: spy};
|
||||
@@ -1060,7 +1044,7 @@ describe('ReactPropTypes', function() {
|
||||
expect(spy.calls.argsFor(0)[1]).toBe('num');
|
||||
});
|
||||
|
||||
it('should have been called even if the prop is not present', function() {
|
||||
it('should have been called even if the prop is not present', () => {
|
||||
var spy = jasmine.createSpy();
|
||||
Component = class extends React.Component {
|
||||
static propTypes = {num: spy};
|
||||
@@ -1077,7 +1061,7 @@ describe('ReactPropTypes', function() {
|
||||
expect(spy.calls.argsFor(0)[1]).toBe('num');
|
||||
});
|
||||
|
||||
it('should have received the validator\'s return value', function() {
|
||||
it('should have received the validator\'s return value', () => {
|
||||
spyOn(console, 'error');
|
||||
var spy = jasmine.createSpy().and.callFake(
|
||||
function(props, propName, componentName) {
|
||||
@@ -1106,7 +1090,7 @@ describe('ReactPropTypes', function() {
|
||||
});
|
||||
|
||||
it('should not warn if the validator returned null',
|
||||
function() {
|
||||
() => {
|
||||
spyOn(console, 'error');
|
||||
var spy = jasmine.createSpy().and.callFake(
|
||||
function(props, propName, componentName) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @flow
|
||||
* @providesModule ReactComponentTreeHook
|
||||
*/
|
||||
|
||||
@@ -16,6 +17,9 @@ var ReactCurrentOwner = require('ReactCurrentOwner');
|
||||
var invariant = require('invariant');
|
||||
var warning = require('warning');
|
||||
|
||||
import type { ReactElement, Source } from 'ReactElementType';
|
||||
import type { DebugID } from 'ReactInstanceType';
|
||||
|
||||
function isNative(fn) {
|
||||
// Based on isNative() from Lodash
|
||||
var funcToString = Function.prototype.toString;
|
||||
@@ -58,112 +62,88 @@ var canUseCollections = (
|
||||
isNative(Set.prototype.keys)
|
||||
);
|
||||
|
||||
var itemMap;
|
||||
var rootIDSet;
|
||||
|
||||
var itemByKey;
|
||||
var rootByKey;
|
||||
|
||||
if (canUseCollections) {
|
||||
itemMap = new Map();
|
||||
rootIDSet = new Set();
|
||||
} else {
|
||||
itemByKey = {};
|
||||
rootByKey = {};
|
||||
}
|
||||
var itemMap = new Map();
|
||||
var rootIDSet = new Set();
|
||||
|
||||
var unmountedIDs = [];
|
||||
|
||||
// Use non-numeric keys to prevent V8 performance issues:
|
||||
// https://github.com/facebook/react/pull/7232
|
||||
function getKeyFromID(id) {
|
||||
return '.' + id;
|
||||
}
|
||||
function getIDFromKey(key) {
|
||||
return parseInt(key.substr(1), 10);
|
||||
}
|
||||
|
||||
function get(id) {
|
||||
if (canUseCollections) {
|
||||
var setItem = function(id, item) {
|
||||
itemMap.set(id, item);
|
||||
};
|
||||
var getItem = function(id) {
|
||||
return itemMap.get(id);
|
||||
} else {
|
||||
var key = getKeyFromID(id);
|
||||
return itemByKey[key];
|
||||
}
|
||||
}
|
||||
|
||||
function remove(id) {
|
||||
if (canUseCollections) {
|
||||
};
|
||||
var removeItem = function(id) {
|
||||
itemMap.delete(id);
|
||||
} else {
|
||||
var key = getKeyFromID(id);
|
||||
delete itemByKey[key];
|
||||
}
|
||||
}
|
||||
|
||||
function create(id, element, parentID) {
|
||||
var item = {
|
||||
element,
|
||||
parentID,
|
||||
text: null,
|
||||
childIDs: [],
|
||||
isMounted: false,
|
||||
updateCount: 0,
|
||||
};
|
||||
var getItemIDs = function() {
|
||||
return Array.from(itemMap.keys());
|
||||
};
|
||||
|
||||
if (canUseCollections) {
|
||||
itemMap.set(id, item);
|
||||
} else {
|
||||
var addRoot = function(id) {
|
||||
rootIDSet.add(id);
|
||||
};
|
||||
var removeRoot = function(id) {
|
||||
rootIDSet.delete(id);
|
||||
};
|
||||
var getRootIDs = function() {
|
||||
return Array.from(rootIDSet.keys());
|
||||
};
|
||||
|
||||
} else {
|
||||
var itemByKey = {};
|
||||
var rootByKey = {};
|
||||
|
||||
// Use non-numeric keys to prevent V8 performance issues:
|
||||
// https://github.com/facebook/react/pull/7232
|
||||
var getKeyFromID = function(id: DebugID): string {
|
||||
return '.' + id;
|
||||
};
|
||||
var getIDFromKey = function(key: string): DebugID {
|
||||
return parseInt(key.substr(1), 10);
|
||||
};
|
||||
|
||||
var setItem = function(id, item) {
|
||||
var key = getKeyFromID(id);
|
||||
itemByKey[key] = item;
|
||||
}
|
||||
}
|
||||
};
|
||||
var getItem = function(id) {
|
||||
var key = getKeyFromID(id);
|
||||
return itemByKey[key];
|
||||
};
|
||||
var removeItem = function(id) {
|
||||
var key = getKeyFromID(id);
|
||||
delete itemByKey[key];
|
||||
};
|
||||
var getItemIDs = function() {
|
||||
return Object.keys(itemByKey).map(getIDFromKey);
|
||||
};
|
||||
|
||||
function addRoot(id) {
|
||||
if (canUseCollections) {
|
||||
rootIDSet.add(id);
|
||||
} else {
|
||||
var addRoot = function(id) {
|
||||
var key = getKeyFromID(id);
|
||||
rootByKey[key] = true;
|
||||
}
|
||||
}
|
||||
|
||||
function removeRoot(id) {
|
||||
if (canUseCollections) {
|
||||
rootIDSet.delete(id);
|
||||
} else {
|
||||
};
|
||||
var removeRoot = function(id) {
|
||||
var key = getKeyFromID(id);
|
||||
delete rootByKey[key];
|
||||
}
|
||||
}
|
||||
|
||||
function getRegisteredIDs() {
|
||||
if (canUseCollections) {
|
||||
return Array.from(itemMap.keys());
|
||||
} else {
|
||||
return Object.keys(itemByKey).map(getIDFromKey);
|
||||
}
|
||||
}
|
||||
|
||||
function getRootIDs() {
|
||||
if (canUseCollections) {
|
||||
return Array.from(rootIDSet.keys());
|
||||
} else {
|
||||
};
|
||||
var getRootIDs = function() {
|
||||
return Object.keys(rootByKey).map(getIDFromKey);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var unmountedIDs: Array<DebugID> = [];
|
||||
|
||||
function purgeDeep(id) {
|
||||
var item = get(id);
|
||||
var item = getItem(id);
|
||||
if (item) {
|
||||
var {childIDs} = item;
|
||||
remove(id);
|
||||
removeItem(id);
|
||||
childIDs.forEach(purgeDeep);
|
||||
}
|
||||
}
|
||||
|
||||
function describeComponentFrame(name, source, ownerName) {
|
||||
return '\n in ' + name + (
|
||||
return '\n in ' + (name || 'Unknown') + (
|
||||
source ?
|
||||
' (at ' + source.fileName.replace(/^.*[\\\/]/, '') + ':' +
|
||||
source.lineNumber + ')' :
|
||||
@@ -173,7 +153,7 @@ function describeComponentFrame(name, source, ownerName) {
|
||||
);
|
||||
}
|
||||
|
||||
function getDisplayName(element) {
|
||||
function getDisplayName(element: ?ReactElement): string {
|
||||
if (element == null) {
|
||||
return '#empty';
|
||||
} else if (typeof element === 'string' || typeof element === 'number') {
|
||||
@@ -185,7 +165,7 @@ function getDisplayName(element) {
|
||||
}
|
||||
}
|
||||
|
||||
function describeID(id) {
|
||||
function describeID(id: DebugID): string {
|
||||
var name = ReactComponentTreeHook.getDisplayName(id);
|
||||
var element = ReactComponentTreeHook.getElement(id);
|
||||
var ownerID = ReactComponentTreeHook.getOwnerID(id);
|
||||
@@ -203,13 +183,14 @@ function describeID(id) {
|
||||
}
|
||||
|
||||
var ReactComponentTreeHook = {
|
||||
onSetChildren(id, nextChildIDs) {
|
||||
var item = get(id);
|
||||
onSetChildren(id: DebugID, nextChildIDs: Array<DebugID>): void {
|
||||
var item = getItem(id);
|
||||
invariant(item, 'Item must have been set');
|
||||
item.childIDs = nextChildIDs;
|
||||
|
||||
for (var i = 0; i < nextChildIDs.length; i++) {
|
||||
var nextChildID = nextChildIDs[i];
|
||||
var nextChild = get(nextChildID);
|
||||
var nextChild = getItem(nextChildID);
|
||||
invariant(
|
||||
nextChild,
|
||||
'Expected hook events to fire for the child ' +
|
||||
@@ -231,7 +212,7 @@ var ReactComponentTreeHook = {
|
||||
nextChild.parentID = id;
|
||||
// TODO: This shouldn't be necessary but mounting a new root during in
|
||||
// componentWillMount currently causes not-yet-mounted components to
|
||||
// be purged from our tree data so their parent ID is missing.
|
||||
// be purged from our tree data so their parent id is missing.
|
||||
}
|
||||
invariant(
|
||||
nextChild.parentID === id,
|
||||
@@ -244,12 +225,20 @@ var ReactComponentTreeHook = {
|
||||
}
|
||||
},
|
||||
|
||||
onBeforeMountComponent(id, element, parentID) {
|
||||
create(id, element, parentID);
|
||||
onBeforeMountComponent(id: DebugID, element: ReactElement, parentID: DebugID): void {
|
||||
var item = {
|
||||
element,
|
||||
parentID,
|
||||
text: null,
|
||||
childIDs: [],
|
||||
isMounted: false,
|
||||
updateCount: 0,
|
||||
};
|
||||
setItem(id, item);
|
||||
},
|
||||
|
||||
onBeforeUpdateComponent(id, element) {
|
||||
var item = get(id);
|
||||
onBeforeUpdateComponent(id: DebugID, element: ReactElement): void {
|
||||
var item = getItem(id);
|
||||
if (!item || !item.isMounted) {
|
||||
// We may end up here as a result of setState() in componentWillUnmount().
|
||||
// In this case, ignore the element.
|
||||
@@ -258,8 +247,9 @@ var ReactComponentTreeHook = {
|
||||
item.element = element;
|
||||
},
|
||||
|
||||
onMountComponent(id) {
|
||||
var item = get(id);
|
||||
onMountComponent(id: DebugID): void {
|
||||
var item = getItem(id);
|
||||
invariant(item, 'Item must have been set');
|
||||
item.isMounted = true;
|
||||
var isRoot = item.parentID === 0;
|
||||
if (isRoot) {
|
||||
@@ -267,8 +257,8 @@ var ReactComponentTreeHook = {
|
||||
}
|
||||
},
|
||||
|
||||
onUpdateComponent(id) {
|
||||
var item = get(id);
|
||||
onUpdateComponent(id: DebugID): void {
|
||||
var item = getItem(id);
|
||||
if (!item || !item.isMounted) {
|
||||
// We may end up here as a result of setState() in componentWillUnmount().
|
||||
// In this case, ignore the element.
|
||||
@@ -277,8 +267,8 @@ var ReactComponentTreeHook = {
|
||||
item.updateCount++;
|
||||
},
|
||||
|
||||
onUnmountComponent(id) {
|
||||
var item = get(id);
|
||||
onUnmountComponent(id: DebugID): void {
|
||||
var item = getItem(id);
|
||||
if (item) {
|
||||
// We need to check if it exists.
|
||||
// `item` might not exist if it is inside an error boundary, and a sibling
|
||||
@@ -294,7 +284,7 @@ var ReactComponentTreeHook = {
|
||||
unmountedIDs.push(id);
|
||||
},
|
||||
|
||||
purgeUnmountedComponents() {
|
||||
purgeUnmountedComponents(): void {
|
||||
if (ReactComponentTreeHook._preventPurging) {
|
||||
// Should only be used for testing.
|
||||
return;
|
||||
@@ -307,21 +297,18 @@ var ReactComponentTreeHook = {
|
||||
unmountedIDs.length = 0;
|
||||
},
|
||||
|
||||
isMounted(id) {
|
||||
var item = get(id);
|
||||
isMounted(id: DebugID): boolean {
|
||||
var item = getItem(id);
|
||||
return item ? item.isMounted : false;
|
||||
},
|
||||
|
||||
getCurrentStackAddendum(topElement) {
|
||||
getCurrentStackAddendum(topElement: ?ReactElement): string {
|
||||
var info = '';
|
||||
if (topElement) {
|
||||
var type = topElement.type;
|
||||
var name = typeof type === 'function' ?
|
||||
type.displayName || type.name :
|
||||
type;
|
||||
var name = getDisplayName(topElement);
|
||||
var owner = topElement._owner;
|
||||
info += describeComponentFrame(
|
||||
name || 'Unknown',
|
||||
name,
|
||||
topElement._source,
|
||||
owner && owner.getName()
|
||||
);
|
||||
@@ -334,7 +321,7 @@ var ReactComponentTreeHook = {
|
||||
return info;
|
||||
},
|
||||
|
||||
getStackAddendumByID(id) {
|
||||
getStackAddendumByID(id: ?DebugID): string {
|
||||
var info = '';
|
||||
while (id) {
|
||||
info += describeID(id);
|
||||
@@ -343,12 +330,12 @@ var ReactComponentTreeHook = {
|
||||
return info;
|
||||
},
|
||||
|
||||
getChildIDs(id) {
|
||||
var item = get(id);
|
||||
getChildIDs(id: DebugID): Array<DebugID> {
|
||||
var item = getItem(id);
|
||||
return item ? item.childIDs : [];
|
||||
},
|
||||
|
||||
getDisplayName(id) {
|
||||
getDisplayName(id: DebugID): ?string {
|
||||
var element = ReactComponentTreeHook.getElement(id);
|
||||
if (!element) {
|
||||
return null;
|
||||
@@ -356,12 +343,12 @@ var ReactComponentTreeHook = {
|
||||
return getDisplayName(element);
|
||||
},
|
||||
|
||||
getElement(id) {
|
||||
var item = get(id);
|
||||
getElement(id: DebugID): ?ReactElement {
|
||||
var item = getItem(id);
|
||||
return item ? item.element : null;
|
||||
},
|
||||
|
||||
getOwnerID(id) {
|
||||
getOwnerID(id: DebugID): ?DebugID {
|
||||
var element = ReactComponentTreeHook.getElement(id);
|
||||
if (!element || !element._owner) {
|
||||
return null;
|
||||
@@ -369,19 +356,19 @@ var ReactComponentTreeHook = {
|
||||
return element._owner._debugID;
|
||||
},
|
||||
|
||||
getParentID(id) {
|
||||
var item = get(id);
|
||||
getParentID(id: DebugID): ?DebugID {
|
||||
var item = getItem(id);
|
||||
return item ? item.parentID : null;
|
||||
},
|
||||
|
||||
getSource(id) {
|
||||
var item = get(id);
|
||||
getSource(id: DebugID): ?Source {
|
||||
var item = getItem(id);
|
||||
var element = item ? item.element : null;
|
||||
var source = element != null ? element._source : null;
|
||||
return source;
|
||||
},
|
||||
|
||||
getText(id) {
|
||||
getText(id: DebugID): ?string {
|
||||
var element = ReactComponentTreeHook.getElement(id);
|
||||
if (typeof element === 'string') {
|
||||
return element;
|
||||
@@ -392,14 +379,13 @@ var ReactComponentTreeHook = {
|
||||
}
|
||||
},
|
||||
|
||||
getUpdateCount(id) {
|
||||
var item = get(id);
|
||||
getUpdateCount(id: DebugID): number {
|
||||
var item = getItem(id);
|
||||
return item ? item.updateCount : 0;
|
||||
},
|
||||
|
||||
getRegisteredIDs,
|
||||
|
||||
getRootIDs,
|
||||
getRegisteredIDs: getItemIDs,
|
||||
};
|
||||
|
||||
module.exports = ReactComponentTreeHook;
|
||||
@@ -14,14 +14,14 @@
|
||||
var spawnSync = require('child_process').spawnSync;
|
||||
var path = require('path');
|
||||
|
||||
describe('ReactClassEquivalence', function() {
|
||||
it('tests the same thing for es6 classes and CoffeeScript', function() {
|
||||
describe('ReactClassEquivalence', () => {
|
||||
it('tests the same thing for es6 classes and CoffeeScript', () => {
|
||||
var result1 = runJest('ReactCoffeeScriptClass-test.coffee');
|
||||
var result2 = runJest('ReactES6Class-test.js');
|
||||
compareResults(result1, result2);
|
||||
});
|
||||
|
||||
it('tests the same thing for es6 classes and TypeScript', function() {
|
||||
it('tests the same thing for es6 classes and TypeScript', () => {
|
||||
var result1 = runJest('ReactTypeScriptClass-test.ts');
|
||||
var result2 = runJest('ReactES6Class-test.js');
|
||||
compareResults(result1, result2);
|
||||
@@ -32,7 +32,11 @@ describe('ReactClassEquivalence', function() {
|
||||
function runJest(testFile) {
|
||||
var cwd = process.cwd();
|
||||
var jestBin = path.resolve('node_modules', '.bin', 'jest');
|
||||
var setupFile = path.resolve(__dirname, 'setupSpecEquivalenceReporter.js');
|
||||
var setupFile = path.resolve(
|
||||
'scripts',
|
||||
'jest',
|
||||
'setupSpecEquivalenceReporter.js'
|
||||
);
|
||||
var result = spawnSync('node', [
|
||||
jestBin,
|
||||
testFile,
|
||||
@@ -60,7 +64,7 @@ function runJest(testFile) {
|
||||
}
|
||||
|
||||
function compareResults(a, b) {
|
||||
var regexp = /^EQUIVALENCE.*$/gm;
|
||||
var regexp = /EQUIVALENCE.*$/gm;
|
||||
var aSpecs = (a.match(regexp) || []).sort().join('\n');
|
||||
var bSpecs = (b.match(regexp) || []).sort().join('\n');
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
var React;
|
||||
var ReactDOM;
|
||||
|
||||
describe('ReactES6Class', function() {
|
||||
describe('ReactES6Class', () => {
|
||||
|
||||
var container;
|
||||
var freeze = function(expectation) {
|
||||
@@ -25,7 +25,7 @@ describe('ReactES6Class', function() {
|
||||
var attachedListener = null;
|
||||
var renderedName = null;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
container = document.createElement('div');
|
||||
@@ -51,12 +51,12 @@ describe('ReactES6Class', function() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
it('preserves the name of the class for use in error messages', function() {
|
||||
it('preserves the name of the class for use in error messages', () => {
|
||||
class Foo extends React.Component { }
|
||||
expect(Foo.name).toBe('Foo');
|
||||
});
|
||||
|
||||
it('throws if no render function is defined', function() {
|
||||
it('throws if no render function is defined', () => {
|
||||
spyOn(console, 'error');
|
||||
class Foo extends React.Component { }
|
||||
expect(() => ReactDOM.render(<Foo />, container)).toThrow();
|
||||
@@ -68,7 +68,7 @@ describe('ReactES6Class', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('renders a simple stateless component with prop', function() {
|
||||
it('renders a simple stateless component with prop', () => {
|
||||
class Foo extends React.Component {
|
||||
render() {
|
||||
return <Inner name={this.props.bar} />;
|
||||
@@ -78,7 +78,7 @@ describe('ReactES6Class', function() {
|
||||
test(<Foo bar="bar" />, 'DIV', 'bar');
|
||||
});
|
||||
|
||||
it('renders based on state using initial values in this.props', function() {
|
||||
it('renders based on state using initial values in this.props', () => {
|
||||
class Foo extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -91,7 +91,7 @@ describe('ReactES6Class', function() {
|
||||
test(<Foo initialValue="foo" />, 'SPAN', 'foo');
|
||||
});
|
||||
|
||||
it('renders based on state using props in the constructor', function() {
|
||||
it('renders based on state using props in the constructor', () => {
|
||||
class Foo extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -112,7 +112,7 @@ describe('ReactES6Class', function() {
|
||||
test(<Foo />, 'SPAN', 'bar');
|
||||
});
|
||||
|
||||
it('renders based on context in the constructor', function() {
|
||||
it('renders based on context in the constructor', () => {
|
||||
class Foo extends React.Component {
|
||||
constructor(props, context) {
|
||||
super(props, context);
|
||||
@@ -143,7 +143,7 @@ describe('ReactES6Class', function() {
|
||||
test(<Outer />, 'SPAN', 'foo');
|
||||
});
|
||||
|
||||
it('renders only once when setting state in componentWillMount', function() {
|
||||
it('renders only once when setting state in componentWillMount', () => {
|
||||
var renderCount = 0;
|
||||
class Foo extends React.Component {
|
||||
constructor(props) {
|
||||
@@ -162,7 +162,7 @@ describe('ReactES6Class', function() {
|
||||
expect(renderCount).toBe(1);
|
||||
});
|
||||
|
||||
it('should throw with non-object in the initial state property', function() {
|
||||
it('should throw with non-object in the initial state property', () => {
|
||||
[['an array'], 'a string', 1234].forEach(function(state) {
|
||||
class Foo extends React.Component {
|
||||
constructor() {
|
||||
@@ -179,7 +179,7 @@ describe('ReactES6Class', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should render with null in the initial state property', function() {
|
||||
it('should render with null in the initial state property', () => {
|
||||
class Foo extends React.Component {
|
||||
constructor() {
|
||||
super();
|
||||
@@ -192,7 +192,7 @@ describe('ReactES6Class', function() {
|
||||
test(<Foo />, 'SPAN', '');
|
||||
});
|
||||
|
||||
it('setState through an event handler', function() {
|
||||
it('setState through an event handler', () => {
|
||||
class Foo extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -215,7 +215,7 @@ describe('ReactES6Class', function() {
|
||||
expect(renderedName).toBe('bar');
|
||||
});
|
||||
|
||||
it('should not implicitly bind event handlers', function() {
|
||||
it('should not implicitly bind event handlers', () => {
|
||||
class Foo extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -237,7 +237,7 @@ describe('ReactES6Class', function() {
|
||||
expect(attachedListener).toThrow();
|
||||
});
|
||||
|
||||
it('renders using forceUpdate even when there is no state', function() {
|
||||
it('renders using forceUpdate even when there is no state', () => {
|
||||
class Foo extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -261,7 +261,7 @@ describe('ReactES6Class', function() {
|
||||
expect(renderedName).toBe('bar');
|
||||
});
|
||||
|
||||
it('will call all the normal life cycle methods', function() {
|
||||
it('will call all the normal life cycle methods', () => {
|
||||
var lifeCycles = [];
|
||||
class Foo extends React.Component {
|
||||
constructor() {
|
||||
@@ -314,7 +314,7 @@ describe('ReactES6Class', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('warns when classic properties are defined on the instance, but does not invoke them.', function() {
|
||||
it('warns when classic properties are defined on the instance, but does not invoke them.', () => {
|
||||
spyOn(console, 'error');
|
||||
var getDefaultPropsWasCalled = false;
|
||||
var getInitialStateWasCalled = false;
|
||||
@@ -354,7 +354,7 @@ describe('ReactES6Class', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when misspelling shouldComponentUpdate', function() {
|
||||
it('should warn when misspelling shouldComponentUpdate', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
class NamedComponent extends React.Component {
|
||||
@@ -376,7 +376,7 @@ describe('ReactES6Class', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when misspelling componentWillReceiveProps', function() {
|
||||
it('should warn when misspelling componentWillReceiveProps', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
class NamedComponent extends React.Component {
|
||||
@@ -397,7 +397,7 @@ describe('ReactES6Class', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw AND warn when trying to access classic APIs', function() {
|
||||
it('should throw AND warn when trying to access classic APIs', () => {
|
||||
spyOn(console, 'error');
|
||||
var instance = test(<Inner name="foo" />, 'DIV', 'foo');
|
||||
expect(() => instance.replaceState({})).toThrow();
|
||||
@@ -411,7 +411,7 @@ describe('ReactES6Class', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('supports this.context passed via getChildContext', function() {
|
||||
it('supports this.context passed via getChildContext', () => {
|
||||
class Bar extends React.Component {
|
||||
render() {
|
||||
return <div className={this.context.bar} />;
|
||||
@@ -430,7 +430,7 @@ describe('ReactES6Class', function() {
|
||||
test(<Foo />, 'DIV', 'bar-through-context');
|
||||
});
|
||||
|
||||
it('supports classic refs', function() {
|
||||
it('supports classic refs', () => {
|
||||
class Foo extends React.Component {
|
||||
render() {
|
||||
return <Inner name="foo" ref="inner" />;
|
||||
@@ -440,7 +440,7 @@ describe('ReactES6Class', function() {
|
||||
expect(instance.refs.inner.getName()).toBe('foo');
|
||||
});
|
||||
|
||||
it('supports drilling through to the DOM using findDOMNode', function() {
|
||||
it('supports drilling through to the DOM using findDOMNode', () => {
|
||||
var instance = test(<Inner name="foo" />, 'DIV', 'foo');
|
||||
var node = ReactDOM.findDOMNode(instance);
|
||||
expect(node).toBe(container.firstChild);
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
var React;
|
||||
var ReactDOM;
|
||||
|
||||
describe('ReactPureComponent', function() {
|
||||
beforeEach(function() {
|
||||
describe('ReactPureComponent', () => {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
});
|
||||
|
||||
it('should render', function() {
|
||||
it('should render', () => {
|
||||
var renders = 0;
|
||||
class Component extends React.PureComponent {
|
||||
constructor() {
|
||||
@@ -63,7 +63,7 @@ describe('ReactPureComponent', function() {
|
||||
expect(renders).toBe(3);
|
||||
});
|
||||
|
||||
it('can override shouldComponentUpdate', function() {
|
||||
it('can override shouldComponentUpdate', () => {
|
||||
var renders = 0;
|
||||
class Component extends React.PureComponent {
|
||||
render() {
|
||||
@@ -80,7 +80,7 @@ describe('ReactPureComponent', function() {
|
||||
expect(renders).toBe(2);
|
||||
});
|
||||
|
||||
it('extends React.Component', function() {
|
||||
it('extends React.Component', () => {
|
||||
var renders = 0;
|
||||
class Component extends React.PureComponent {
|
||||
render() {
|
||||
|
||||
@@ -15,10 +15,10 @@ var React;
|
||||
var ReactDOM;
|
||||
var ReactTestUtils;
|
||||
|
||||
describe('ReactJSXElement', function() {
|
||||
describe('ReactJSXElement', () => {
|
||||
var Component;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
|
||||
React = require('React');
|
||||
@@ -31,7 +31,7 @@ describe('ReactJSXElement', function() {
|
||||
};
|
||||
});
|
||||
|
||||
it('returns a complete element according to spec', function() {
|
||||
it('returns a complete element according to spec', () => {
|
||||
var element = <Component />;
|
||||
expect(element.type).toBe(Component);
|
||||
expect(element.key).toBe(null);
|
||||
@@ -41,7 +41,7 @@ describe('ReactJSXElement', function() {
|
||||
expect(element.props).toEqual(expectation);
|
||||
});
|
||||
|
||||
it('allows a lower-case to be passed as the string type', function() {
|
||||
it('allows a lower-case to be passed as the string type', () => {
|
||||
var element = <div />;
|
||||
expect(element.type).toBe('div');
|
||||
expect(element.key).toBe(null);
|
||||
@@ -51,7 +51,7 @@ describe('ReactJSXElement', function() {
|
||||
expect(element.props).toEqual(expectation);
|
||||
});
|
||||
|
||||
it('allows a string to be passed as the type', function() {
|
||||
it('allows a string to be passed as the type', () => {
|
||||
var TagName = 'div';
|
||||
var element = <TagName />;
|
||||
expect(element.type).toBe('div');
|
||||
@@ -62,12 +62,12 @@ describe('ReactJSXElement', function() {
|
||||
expect(element.props).toEqual(expectation);
|
||||
});
|
||||
|
||||
it('returns an immutable element', function() {
|
||||
it('returns an immutable element', () => {
|
||||
var element = <Component />;
|
||||
expect(() => element.type = 'div').toThrow();
|
||||
});
|
||||
|
||||
it('does not reuse the object that is spread into props', function() {
|
||||
it('does not reuse the object that is spread into props', () => {
|
||||
var config = {foo: 1};
|
||||
var element = <Component {...config} />;
|
||||
expect(element.props.foo).toBe(1);
|
||||
@@ -75,7 +75,7 @@ describe('ReactJSXElement', function() {
|
||||
expect(element.props.foo).toBe(1);
|
||||
});
|
||||
|
||||
it('extracts key and ref from the rest of the props', function() {
|
||||
it('extracts key and ref from the rest of the props', () => {
|
||||
var element = <Component key="12" ref="34" foo="56" />;
|
||||
expect(element.type).toBe(Component);
|
||||
expect(element.key).toBe('12');
|
||||
@@ -85,7 +85,7 @@ describe('ReactJSXElement', function() {
|
||||
expect(element.props).toEqual(expectation);
|
||||
});
|
||||
|
||||
it('coerces the key to a string', function() {
|
||||
it('coerces the key to a string', () => {
|
||||
var element = <Component key={12} foo="56" />;
|
||||
expect(element.type).toBe(Component);
|
||||
expect(element.key).toBe('12');
|
||||
@@ -95,7 +95,7 @@ describe('ReactJSXElement', function() {
|
||||
expect(element.props).toEqual(expectation);
|
||||
});
|
||||
|
||||
it('merges JSX children onto the children prop', function() {
|
||||
it('merges JSX children onto the children prop', () => {
|
||||
spyOn(console, 'error');
|
||||
var a = 1;
|
||||
var element = <Component children="text">{a}</Component>;
|
||||
@@ -103,21 +103,21 @@ describe('ReactJSXElement', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not override children if no JSX children are provided', function() {
|
||||
it('does not override children if no JSX children are provided', () => {
|
||||
spyOn(console, 'error');
|
||||
var element = <Component children="text" />;
|
||||
expect(element.props.children).toBe('text');
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('overrides children if null is provided as a JSX child', function() {
|
||||
it('overrides children if null is provided as a JSX child', () => {
|
||||
spyOn(console, 'error');
|
||||
var element = <Component children="text">{null}</Component>;
|
||||
expect(element.props.children).toBe(null);
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('overrides children if undefined is provided as an argument', function() {
|
||||
it('overrides children if undefined is provided as an argument', () => {
|
||||
var element = <Component children="text">{undefined}</Component>;
|
||||
expect(element.props.children).toBe(undefined);
|
||||
|
||||
@@ -129,7 +129,7 @@ describe('ReactJSXElement', function() {
|
||||
expect(element2.props.children).toBe(undefined);
|
||||
});
|
||||
|
||||
it('merges JSX children onto the children prop in an array', function() {
|
||||
it('merges JSX children onto the children prop in an array', () => {
|
||||
spyOn(console, 'error');
|
||||
var a = 1;
|
||||
var b = 2;
|
||||
@@ -139,7 +139,7 @@ describe('ReactJSXElement', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('allows static methods to be called using the type property', function() {
|
||||
it('allows static methods to be called using the type property', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
class StaticMethodComponent {
|
||||
@@ -156,7 +156,7 @@ describe('ReactJSXElement', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('identifies valid elements', function() {
|
||||
it('identifies valid elements', () => {
|
||||
expect(React.isValidElement(<div />)).toEqual(true);
|
||||
expect(React.isValidElement(<Component />)).toEqual(true);
|
||||
|
||||
@@ -168,13 +168,13 @@ describe('ReactJSXElement', function() {
|
||||
expect(React.isValidElement({ type: 'div', props: {} })).toEqual(false);
|
||||
});
|
||||
|
||||
it('is indistinguishable from a plain object', function() {
|
||||
it('is indistinguishable from a plain object', () => {
|
||||
var element = <div className="foo" />;
|
||||
var object = {};
|
||||
expect(element.constructor).toBe(object.constructor);
|
||||
});
|
||||
|
||||
it('should use default prop value when removing a prop', function() {
|
||||
it('should use default prop value when removing a prop', () => {
|
||||
Component.defaultProps = {fruit: 'persimmon'};
|
||||
|
||||
var container = document.createElement('div');
|
||||
@@ -188,7 +188,7 @@ describe('ReactJSXElement', function() {
|
||||
expect(instance.props.fruit).toBe('persimmon');
|
||||
});
|
||||
|
||||
it('should normalize props with default values', function() {
|
||||
it('should normalize props with default values', () => {
|
||||
class NormalizingComponent extends React.Component {
|
||||
render() {
|
||||
return <span>{this.props.prop}</span>;
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
var React;
|
||||
var ReactTestUtils;
|
||||
|
||||
describe('ReactJSXElementValidator', function() {
|
||||
describe('ReactJSXElementValidator', () => {
|
||||
var Component;
|
||||
var RequiredPropComponent;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
|
||||
React = require('React');
|
||||
@@ -42,7 +42,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
RequiredPropComponent.propTypes = {prop: React.PropTypes.string.isRequired};
|
||||
});
|
||||
|
||||
it('warns for keys for arrays of elements in children position', function() {
|
||||
it('warns for keys for arrays of elements in children position', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
void <Component>{[<Component />, <Component />]}</Component>;
|
||||
@@ -53,7 +53,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('warns for keys for arrays of elements with owner info', function() {
|
||||
it('warns for keys for arrays of elements with owner info', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
class InnerComponent extends React.Component {
|
||||
@@ -82,7 +82,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('warns for keys for iterables of elements in rest args', function() {
|
||||
it('warns for keys for iterables of elements in rest args', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var iterable = {
|
||||
@@ -105,7 +105,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('does not warns for arrays of elements with keys', function() {
|
||||
it('does not warns for arrays of elements with keys', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
void <Component>{[<Component key="#1" />, <Component key="#2" />]}</Component>;
|
||||
@@ -113,7 +113,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not warns for iterable elements with keys', function() {
|
||||
it('does not warns for iterable elements with keys', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var iterable = {
|
||||
@@ -136,7 +136,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not warn for numeric keys in entry iterable as a child', function() {
|
||||
it('does not warn for numeric keys in entry iterable as a child', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
var iterable = {
|
||||
@@ -157,7 +157,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not warn when the element is directly as children', function() {
|
||||
it('does not warn when the element is directly as children', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
void <Component><Component /><Component /></Component>;
|
||||
@@ -165,7 +165,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('does not warn when the child array contains non-elements', function() {
|
||||
it('does not warn when the child array contains non-elements', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
void <Component>{[{}, {}]}</Component>;
|
||||
@@ -238,7 +238,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(4);
|
||||
});
|
||||
|
||||
it('should check default prop values', function() {
|
||||
it('should check default prop values', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
RequiredPropComponent.defaultProps = {prop: null};
|
||||
@@ -249,13 +249,13 @@ describe('ReactJSXElementValidator', function() {
|
||||
expect(
|
||||
console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
|
||||
).toBe(
|
||||
'Warning: Failed prop type: ' +
|
||||
'Required prop `prop` was not specified in `RequiredPropComponent`.\n' +
|
||||
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
|
||||
'`RequiredPropComponent`, but its value is `null`.\n' +
|
||||
' in RequiredPropComponent (at **)'
|
||||
);
|
||||
});
|
||||
|
||||
it('should not check the default for explicit null', function() {
|
||||
it('should not check the default for explicit null', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
ReactTestUtils.renderIntoDocument(<RequiredPropComponent prop={null} />);
|
||||
@@ -264,13 +264,13 @@ describe('ReactJSXElementValidator', function() {
|
||||
expect(
|
||||
console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
|
||||
).toBe(
|
||||
'Warning: Failed prop type: ' +
|
||||
'Required prop `prop` was not specified in `RequiredPropComponent`.\n' +
|
||||
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
|
||||
'`RequiredPropComponent`, but its value is `null`.\n' +
|
||||
' in RequiredPropComponent (at **)'
|
||||
);
|
||||
});
|
||||
|
||||
it('should check declared prop types', function() {
|
||||
it('should check declared prop types', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
ReactTestUtils.renderIntoDocument(<RequiredPropComponent />);
|
||||
@@ -281,7 +281,8 @@ describe('ReactJSXElementValidator', function() {
|
||||
console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
|
||||
).toBe(
|
||||
'Warning: Failed prop type: ' +
|
||||
'Required prop `prop` was not specified in `RequiredPropComponent`.\n' +
|
||||
'The prop `prop` is marked as required in `RequiredPropComponent`, but ' +
|
||||
'its value is `undefined`.\n' +
|
||||
' in RequiredPropComponent (at **)'
|
||||
);
|
||||
|
||||
@@ -300,7 +301,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
expect(console.error.calls.count()).toBe(2);
|
||||
});
|
||||
|
||||
it('should warn on invalid prop types', function() {
|
||||
it('should warn on invalid prop types', () => {
|
||||
// Since there is no prevalidation step for ES6 classes, there is no hook
|
||||
// for us to issue a warning earlier than element creation when the error
|
||||
// actually occurs. Since this step is skipped in production, we should just
|
||||
@@ -322,7 +323,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn on invalid context types', function() {
|
||||
it('should warn on invalid context types', () => {
|
||||
spyOn(console, 'error');
|
||||
class NullContextTypeComponent extends React.Component {
|
||||
render() {
|
||||
@@ -340,7 +341,7 @@ describe('ReactJSXElementValidator', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if getDefaultProps is specificed on the class', function() {
|
||||
it('should warn if getDefaultProps is specificed on the class', () => {
|
||||
spyOn(console, 'error');
|
||||
class GetDefaultPropsComponent extends React.Component {
|
||||
render() {
|
||||
|
||||
@@ -13,9 +13,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
jest
|
||||
.unmock('ReactART');
|
||||
|
||||
var React = require('React');
|
||||
var ReactDOM = require('ReactDOM');
|
||||
var ReactTestUtils = require('ReactTestUtils');
|
||||
@@ -51,9 +48,9 @@ function testDOMNodeStructure(domNode, expectedStructure) {
|
||||
}
|
||||
}
|
||||
|
||||
describe('ReactART', function() {
|
||||
describe('ReactART', () => {
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
ARTCurrentMode.setCurrent(ARTSVGMode);
|
||||
|
||||
Group = ReactART.Group;
|
||||
@@ -99,7 +96,7 @@ describe('ReactART', function() {
|
||||
};
|
||||
});
|
||||
|
||||
it('should have the correct lifecycle state', function() {
|
||||
it('should have the correct lifecycle state', () => {
|
||||
var instance = <TestComponent />;
|
||||
instance = ReactTestUtils.renderIntoDocument(instance);
|
||||
var group = instance.refs.group;
|
||||
@@ -107,7 +104,7 @@ describe('ReactART', function() {
|
||||
expect(typeof group.indicate).toBe('function');
|
||||
});
|
||||
|
||||
it('should render a reasonable SVG structure in SVG mode', function() {
|
||||
it('should render a reasonable SVG structure in SVG mode', () => {
|
||||
var instance = <TestComponent />;
|
||||
instance = ReactTestUtils.renderIntoDocument(instance);
|
||||
|
||||
@@ -138,7 +135,7 @@ describe('ReactART', function() {
|
||||
testDOMNodeStructure(realNode, expectedStructure);
|
||||
});
|
||||
|
||||
it('should be able to reorder components', function() {
|
||||
it('should be able to reorder components', () => {
|
||||
var container = document.createElement('div');
|
||||
var instance = ReactDOM.render(<TestComponent flipped={false} />, container);
|
||||
|
||||
@@ -182,7 +179,7 @@ describe('ReactART', function() {
|
||||
testDOMNodeStructure(realNode, expectedNewStructure);
|
||||
});
|
||||
|
||||
it('should be able to reorder many components', function() {
|
||||
it('should be able to reorder many components', () => {
|
||||
var container = document.createElement('div');
|
||||
|
||||
class Component extends React.Component {
|
||||
@@ -210,7 +207,7 @@ describe('ReactART', function() {
|
||||
ReactDOM.unmountComponentAtNode(container);
|
||||
});
|
||||
|
||||
it('renders composite with lifecycle inside group', function() {
|
||||
it('renders composite with lifecycle inside group', () => {
|
||||
var mounted = false;
|
||||
|
||||
class CustomShape extends React.Component {
|
||||
@@ -233,7 +230,7 @@ describe('ReactART', function() {
|
||||
expect(mounted).toBe(true);
|
||||
});
|
||||
|
||||
it('resolves refs before componentDidMount', function() {
|
||||
it('resolves refs before componentDidMount', () => {
|
||||
class CustomShape extends React.Component {
|
||||
render() {
|
||||
return <Shape />;
|
||||
@@ -262,7 +259,7 @@ describe('ReactART', function() {
|
||||
expect(ref.constructor).toBe(CustomShape);
|
||||
});
|
||||
|
||||
it('resolves refs before componentDidUpdate', function() {
|
||||
it('resolves refs before componentDidUpdate', () => {
|
||||
class CustomShape extends React.Component {
|
||||
render() {
|
||||
return <Shape />;
|
||||
|
||||
@@ -118,7 +118,6 @@ if (__DEV__) {
|
||||
Date.now,
|
||||
Function.prototype.bind,
|
||||
Object.keys,
|
||||
String.prototype.split,
|
||||
String.prototype.trim,
|
||||
];
|
||||
|
||||
@@ -139,9 +138,11 @@ if (__DEV__) {
|
||||
var ReactInstrumentation = require('ReactInstrumentation');
|
||||
var ReactDOMUnknownPropertyHook = require('ReactDOMUnknownPropertyHook');
|
||||
var ReactDOMNullInputValuePropHook = require('ReactDOMNullInputValuePropHook');
|
||||
var ReactDOMInvalidARIAHook = require('ReactDOMInvalidARIAHook');
|
||||
|
||||
ReactInstrumentation.debugTool.addHook(ReactDOMUnknownPropertyHook);
|
||||
ReactInstrumentation.debugTool.addHook(ReactDOMNullInputValuePropHook);
|
||||
ReactInstrumentation.debugTool.addHook(ReactDOMInvalidARIAHook);
|
||||
}
|
||||
|
||||
module.exports = ReactDOM;
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright 2013-2015, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
|
||||
|
||||
var useFiber = ReactDOMFeatureFlags.useFiber;
|
||||
|
||||
module.exports =
|
||||
useFiber ? require('ReactDOMFiber') : require.requireActual('ReactDOM');
|
||||
@@ -10,13 +10,13 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
describe('ReactDOMProduction', function() {
|
||||
describe('ReactDOMProduction', () => {
|
||||
var oldProcess;
|
||||
|
||||
var React;
|
||||
var ReactDOM;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
__DEV__ = false;
|
||||
oldProcess = process;
|
||||
global.process = {env: {NODE_ENV: 'production'}};
|
||||
@@ -26,12 +26,12 @@ describe('ReactDOMProduction', function() {
|
||||
ReactDOM = require('ReactDOM');
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
afterEach(() => {
|
||||
__DEV__ = true;
|
||||
global.process = oldProcess;
|
||||
});
|
||||
|
||||
it('should use prod fbjs', function() {
|
||||
it('should use prod fbjs', () => {
|
||||
var warning = require('warning');
|
||||
|
||||
spyOn(console, 'error');
|
||||
@@ -39,7 +39,7 @@ describe('ReactDOMProduction', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('should use prod React', function() {
|
||||
it('should use prod React', () => {
|
||||
spyOn(console, 'error');
|
||||
|
||||
// no key warning
|
||||
@@ -48,7 +48,7 @@ describe('ReactDOMProduction', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('should handle a simple flow', function() {
|
||||
it('should handle a simple flow', () => {
|
||||
class Component extends React.Component {
|
||||
render() {
|
||||
return <span>{this.props.children}</span>;
|
||||
@@ -86,7 +86,7 @@ describe('ReactDOMProduction', function() {
|
||||
expect(container.childNodes.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should call lifecycle methods', function() {
|
||||
it('should call lifecycle methods', () => {
|
||||
var log = [];
|
||||
class Component extends React.Component {
|
||||
state = {y: 1};
|
||||
@@ -174,7 +174,7 @@ describe('ReactDOMProduction', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should throw with an error code in production', function() {
|
||||
it('should throw with an error code in production', () => {
|
||||
expect(function() {
|
||||
class Component extends React.Component {
|
||||
render() {
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var EventConstants = require('EventConstants');
|
||||
var EventPluginRegistry = require('EventPluginRegistry');
|
||||
var ReactEventEmitterMixin = require('ReactEventEmitterMixin');
|
||||
var ViewportMetrics = require('ViewportMetrics');
|
||||
@@ -241,23 +240,22 @@ var ReactBrowserEventEmitter = Object.assign({}, ReactEventEmitterMixin, {
|
||||
var dependencies =
|
||||
EventPluginRegistry.registrationNameDependencies[registrationName];
|
||||
|
||||
var topLevelTypes = EventConstants.topLevelTypes;
|
||||
for (var i = 0; i < dependencies.length; i++) {
|
||||
var dependency = dependencies[i];
|
||||
if (!(
|
||||
isListening.hasOwnProperty(dependency) &&
|
||||
isListening[dependency]
|
||||
)) {
|
||||
if (dependency === topLevelTypes.topWheel) {
|
||||
if (dependency === 'topWheel') {
|
||||
if (isEventSupported('wheel')) {
|
||||
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(
|
||||
topLevelTypes.topWheel,
|
||||
'topWheel',
|
||||
'wheel',
|
||||
mountAt
|
||||
);
|
||||
} else if (isEventSupported('mousewheel')) {
|
||||
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(
|
||||
topLevelTypes.topWheel,
|
||||
'topWheel',
|
||||
'mousewheel',
|
||||
mountAt
|
||||
);
|
||||
@@ -265,37 +263,37 @@ var ReactBrowserEventEmitter = Object.assign({}, ReactEventEmitterMixin, {
|
||||
// Firefox needs to capture a different mouse scroll event.
|
||||
// @see http://www.quirksmode.org/dom/events/tests/scroll.html
|
||||
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(
|
||||
topLevelTypes.topWheel,
|
||||
'topWheel',
|
||||
'DOMMouseScroll',
|
||||
mountAt
|
||||
);
|
||||
}
|
||||
} else if (dependency === topLevelTypes.topScroll) {
|
||||
} else if (dependency === 'topScroll') {
|
||||
|
||||
if (isEventSupported('scroll', true)) {
|
||||
ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent(
|
||||
topLevelTypes.topScroll,
|
||||
'topScroll',
|
||||
'scroll',
|
||||
mountAt
|
||||
);
|
||||
} else {
|
||||
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(
|
||||
topLevelTypes.topScroll,
|
||||
'topScroll',
|
||||
'scroll',
|
||||
ReactBrowserEventEmitter.ReactEventListener.WINDOW_HANDLE
|
||||
);
|
||||
}
|
||||
} else if (dependency === topLevelTypes.topFocus ||
|
||||
dependency === topLevelTypes.topBlur) {
|
||||
} else if (dependency === 'topFocus' ||
|
||||
dependency === 'topBlur') {
|
||||
|
||||
if (isEventSupported('focus', true)) {
|
||||
ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent(
|
||||
topLevelTypes.topFocus,
|
||||
'topFocus',
|
||||
'focus',
|
||||
mountAt
|
||||
);
|
||||
ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent(
|
||||
topLevelTypes.topBlur,
|
||||
'topBlur',
|
||||
'blur',
|
||||
mountAt
|
||||
);
|
||||
@@ -303,20 +301,20 @@ var ReactBrowserEventEmitter = Object.assign({}, ReactEventEmitterMixin, {
|
||||
// IE has `focusin` and `focusout` events which bubble.
|
||||
// @see http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html
|
||||
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(
|
||||
topLevelTypes.topFocus,
|
||||
'topFocus',
|
||||
'focusin',
|
||||
mountAt
|
||||
);
|
||||
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(
|
||||
topLevelTypes.topBlur,
|
||||
'topBlur',
|
||||
'focusout',
|
||||
mountAt
|
||||
);
|
||||
}
|
||||
|
||||
// to make sure blur and focus event listeners are only attached once
|
||||
isListening[topLevelTypes.topBlur] = true;
|
||||
isListening[topLevelTypes.topFocus] = true;
|
||||
isListening.topBlur = true;
|
||||
isListening.topFocus = true;
|
||||
} else if (topEventMapping.hasOwnProperty(dependency)) {
|
||||
ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent(
|
||||
dependency,
|
||||
|
||||
@@ -90,10 +90,10 @@ function traverseTwoPhase(inst, fn, arg) {
|
||||
}
|
||||
var i;
|
||||
for (i = path.length; i-- > 0;) {
|
||||
fn(path[i], false, arg);
|
||||
fn(path[i], 'captured', arg);
|
||||
}
|
||||
for (i = 0; i < path.length; i++) {
|
||||
fn(path[i], true, arg);
|
||||
fn(path[i], 'bubbled', arg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,10 +118,10 @@ function traverseEnterLeave(from, to, fn, argFrom, argTo) {
|
||||
}
|
||||
var i;
|
||||
for (i = 0; i < pathFrom.length; i++) {
|
||||
fn(pathFrom[i], true, argFrom);
|
||||
fn(pathFrom[i], 'bubbled', argFrom);
|
||||
}
|
||||
for (i = pathTo.length; i-- > 0;) {
|
||||
fn(pathTo[i], false, argTo);
|
||||
fn(pathTo[i], 'captured', argTo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,13 +111,12 @@ var ReactEventListener = {
|
||||
*
|
||||
* @param {string} topLevelType Record from `EventConstants`.
|
||||
* @param {string} handlerBaseName Event name (e.g. "click").
|
||||
* @param {object} handle Element on which to attach listener.
|
||||
* @param {object} element Element on which to attach listener.
|
||||
* @return {?object} An object with a remove function which will forcefully
|
||||
* remove the listener.
|
||||
* @internal
|
||||
*/
|
||||
trapBubbledEvent: function(topLevelType, handlerBaseName, handle) {
|
||||
var element = handle;
|
||||
trapBubbledEvent: function(topLevelType, handlerBaseName, element) {
|
||||
if (!element) {
|
||||
return null;
|
||||
}
|
||||
@@ -133,13 +132,12 @@ var ReactEventListener = {
|
||||
*
|
||||
* @param {string} topLevelType Record from `EventConstants`.
|
||||
* @param {string} handlerBaseName Event name (e.g. "click").
|
||||
* @param {object} handle Element on which to attach listener.
|
||||
* @param {object} element Element on which to attach listener.
|
||||
* @return {?object} An object with a remove function which will forcefully
|
||||
* remove the listener.
|
||||
* @internal
|
||||
*/
|
||||
trapCapturedEvent: function(topLevelType, handlerBaseName, handle) {
|
||||
var element = handle;
|
||||
trapCapturedEvent: function(topLevelType, handlerBaseName, element) {
|
||||
if (!element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
|
||||
var DOMLazyTree = require('DOMLazyTree');
|
||||
var DOMProperty = require('DOMProperty');
|
||||
var React = require('React');
|
||||
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
|
||||
var ReactCurrentOwner = require('ReactCurrentOwner');
|
||||
var ReactDOMComponentTree = require('ReactDOMComponentTree');
|
||||
var ReactDOMContainerInfo = require('ReactDOMContainerInfo');
|
||||
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
|
||||
var ReactElement = require('ReactElement');
|
||||
var ReactFeatureFlags = require('ReactFeatureFlags');
|
||||
var ReactInstanceMap = require('ReactInstanceMap');
|
||||
var ReactInstrumentation = require('ReactInstrumentation');
|
||||
@@ -100,7 +100,7 @@ function mountComponentIntoNode(
|
||||
) {
|
||||
var markerName;
|
||||
if (ReactFeatureFlags.logTopLevelRenders) {
|
||||
var wrappedElement = wrapperInstance._currentElement.props;
|
||||
var wrappedElement = wrapperInstance._currentElement.props.child;
|
||||
var type = wrappedElement.type;
|
||||
markerName = 'React mount: ' + (
|
||||
typeof type === 'string' ? type :
|
||||
@@ -275,9 +275,9 @@ if (__DEV__) {
|
||||
TopLevelWrapper.displayName = 'TopLevelWrapper';
|
||||
}
|
||||
TopLevelWrapper.prototype.render = function() {
|
||||
// this.props is actually a ReactElement
|
||||
return this.props;
|
||||
return this.props.child;
|
||||
};
|
||||
TopLevelWrapper.isReactTopLevelWrapper = true;
|
||||
|
||||
/**
|
||||
* Mounting is the process of initializing a React component by creating its
|
||||
@@ -423,7 +423,7 @@ var ReactMount = {
|
||||
_renderSubtreeIntoContainer: function(parentComponent, nextElement, container, callback) {
|
||||
ReactUpdateQueue.validateCallback(callback, 'ReactDOM.render');
|
||||
invariant(
|
||||
ReactElement.isValidElement(nextElement),
|
||||
React.isValidElement(nextElement),
|
||||
'ReactDOM.render(): Invalid component element.%s',
|
||||
(
|
||||
typeof nextElement === 'string' ?
|
||||
@@ -450,14 +450,9 @@ var ReactMount = {
|
||||
'for your app.'
|
||||
);
|
||||
|
||||
var nextWrappedElement = ReactElement(
|
||||
var nextWrappedElement = React.createElement(
|
||||
TopLevelWrapper,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
nextElement
|
||||
{ child: nextElement }
|
||||
);
|
||||
|
||||
var nextContext;
|
||||
@@ -472,7 +467,7 @@ var ReactMount = {
|
||||
|
||||
if (prevComponent) {
|
||||
var prevWrappedElement = prevComponent._currentElement;
|
||||
var prevElement = prevWrappedElement.props;
|
||||
var prevElement = prevWrappedElement.props.child;
|
||||
if (shouldUpdateReactComponent(prevElement, nextElement)) {
|
||||
var publicInst = prevComponent._renderedComponent.getPublicInstance();
|
||||
var updatedCallback = callback && function() {
|
||||
@@ -734,11 +729,11 @@ var ReactMount = {
|
||||
if (__DEV__) {
|
||||
var hostNode = ReactDOMComponentTree.getInstanceFromNode(container.firstChild);
|
||||
if (hostNode._debugID !== 0) {
|
||||
ReactInstrumentation.debugTool.onHostOperation(
|
||||
hostNode._debugID,
|
||||
'mount',
|
||||
markup.toString()
|
||||
);
|
||||
ReactInstrumentation.debugTool.onHostOperation({
|
||||
instanceID: hostNode._debugID,
|
||||
type: 'mount',
|
||||
payload: markup.toString(),
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -175,7 +175,7 @@ var Mixin = {
|
||||
};
|
||||
|
||||
|
||||
Object.assign(ReactReconcileTransaction.prototype, Transaction.Mixin, Mixin);
|
||||
Object.assign(ReactReconcileTransaction.prototype, Transaction, Mixin);
|
||||
|
||||
PooledClass.addPoolingTo(ReactReconcileTransaction);
|
||||
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var keyOf = require('keyOf');
|
||||
|
||||
var EventListener;
|
||||
var EventPluginHub;
|
||||
var EventPluginRegistry;
|
||||
@@ -36,10 +34,10 @@ var recordIDAndReturnFalse = function(id, event) {
|
||||
return false;
|
||||
};
|
||||
var LISTENER = jest.fn();
|
||||
var ON_CLICK_KEY = keyOf({onClick: null});
|
||||
var ON_TOUCH_TAP_KEY = keyOf({onTouchTap: null});
|
||||
var ON_CHANGE_KEY = keyOf({onChange: null});
|
||||
var ON_MOUSE_ENTER_KEY = keyOf({onMouseEnter: null});
|
||||
var ON_CLICK_KEY = 'onClick';
|
||||
var ON_TOUCH_TAP_KEY = 'onTouchTap';
|
||||
var ON_CHANGE_KEY = 'onChange';
|
||||
var ON_MOUSE_ENTER_KEY = 'onMouseEnter';
|
||||
|
||||
var GRANDPARENT;
|
||||
var PARENT;
|
||||
@@ -57,8 +55,8 @@ function getInternal(node) {
|
||||
}
|
||||
|
||||
|
||||
describe('ReactBrowserEventEmitter', function() {
|
||||
beforeEach(function() {
|
||||
describe('ReactBrowserEventEmitter', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
LISTENER.mockClear();
|
||||
EventListener = require('EventListener');
|
||||
@@ -85,26 +83,26 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should store a listener correctly', function() {
|
||||
it('should store a listener correctly', () => {
|
||||
registerSimpleTestHandler();
|
||||
var listener = EventPluginHub.getListener(getInternal(CHILD), ON_CLICK_KEY);
|
||||
expect(listener).toBe(LISTENER);
|
||||
});
|
||||
|
||||
it('should retrieve a listener correctly', function() {
|
||||
it('should retrieve a listener correctly', () => {
|
||||
registerSimpleTestHandler();
|
||||
var listener = EventPluginHub.getListener(getInternal(CHILD), ON_CLICK_KEY);
|
||||
expect(listener).toEqual(LISTENER);
|
||||
});
|
||||
|
||||
it('should clear all handlers when asked to', function() {
|
||||
it('should clear all handlers when asked to', () => {
|
||||
registerSimpleTestHandler();
|
||||
EventPluginHub.deleteAllListeners(getInternal(CHILD));
|
||||
var listener = EventPluginHub.getListener(getInternal(CHILD), ON_CLICK_KEY);
|
||||
expect(listener).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should invoke a simple handler registered on a node', function() {
|
||||
it('should invoke a simple handler registered on a node', () => {
|
||||
registerSimpleTestHandler();
|
||||
ReactTestUtils.Simulate.click(CHILD);
|
||||
expect(LISTENER.mock.calls.length).toBe(1);
|
||||
@@ -112,7 +110,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
|
||||
it(
|
||||
'should not invoke handlers if ReactBrowserEventEmitter is disabled',
|
||||
function() {
|
||||
() => {
|
||||
registerSimpleTestHandler();
|
||||
ReactBrowserEventEmitter.setEnabled(false);
|
||||
ReactTestUtils.SimulateNative.click(CHILD);
|
||||
@@ -123,7 +121,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
}
|
||||
);
|
||||
|
||||
it('should bubble simply', function() {
|
||||
it('should bubble simply', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_CLICK_KEY,
|
||||
@@ -146,7 +144,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(idCallOrder[2]).toBe(getInternal(GRANDPARENT));
|
||||
});
|
||||
|
||||
it('should continue bubbling if an error is thrown', function() {
|
||||
it('should continue bubbling if an error is thrown', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_CLICK_KEY,
|
||||
@@ -174,7 +172,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(idCallOrder[2]).toBe(getInternal(GRANDPARENT));
|
||||
});
|
||||
|
||||
it('should set currentTarget', function() {
|
||||
it('should set currentTarget', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_CLICK_KEY,
|
||||
@@ -206,7 +204,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(idCallOrder[2]).toBe(getInternal(GRANDPARENT));
|
||||
});
|
||||
|
||||
it('should support stopPropagation()', function() {
|
||||
it('should support stopPropagation()', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_CLICK_KEY,
|
||||
@@ -228,7 +226,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(idCallOrder[1]).toBe(getInternal(PARENT));
|
||||
});
|
||||
|
||||
it('should stop after first dispatch if stopPropagation', function() {
|
||||
it('should stop after first dispatch if stopPropagation', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_CLICK_KEY,
|
||||
@@ -249,7 +247,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(idCallOrder[0]).toBe(getInternal(CHILD));
|
||||
});
|
||||
|
||||
it('should not stopPropagation if false is returned', function() {
|
||||
it('should not stopPropagation if false is returned', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_CLICK_KEY,
|
||||
@@ -283,7 +281,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
* these new listeners.
|
||||
*/
|
||||
|
||||
it('should invoke handlers that were removed while bubbling', function() {
|
||||
it('should invoke handlers that were removed while bubbling', () => {
|
||||
var handleParentClick = jest.fn();
|
||||
var handleChildClick = function(event) {
|
||||
EventPluginHub.deleteAllListeners(getInternal(PARENT));
|
||||
@@ -302,7 +300,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(handleParentClick.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should not invoke newly inserted handlers while bubbling', function() {
|
||||
it('should not invoke newly inserted handlers while bubbling', () => {
|
||||
var handleParentClick = jest.fn();
|
||||
var handleChildClick = function(event) {
|
||||
EventPluginHub.putListener(
|
||||
@@ -320,7 +318,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(handleParentClick.mock.calls.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should have mouse enter simulated by test utils', function() {
|
||||
it('should have mouse enter simulated by test utils', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_MOUSE_ENTER_KEY,
|
||||
@@ -331,7 +329,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(idCallOrder[0]).toBe(getInternal(CHILD));
|
||||
});
|
||||
|
||||
it('should infer onTouchTap from a touchStart/End', function() {
|
||||
it('should infer onTouchTap from a touchStart/End', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_TOUCH_TAP_KEY,
|
||||
@@ -349,7 +347,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(idCallOrder[0]).toBe(getInternal(CHILD));
|
||||
});
|
||||
|
||||
it('should infer onTouchTap from when dragging below threshold', function() {
|
||||
it('should infer onTouchTap from when dragging below threshold', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_TOUCH_TAP_KEY,
|
||||
@@ -367,7 +365,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(idCallOrder[0]).toBe(getInternal(CHILD));
|
||||
});
|
||||
|
||||
it('should not onTouchTap from when dragging beyond threshold', function() {
|
||||
it('should not onTouchTap from when dragging beyond threshold', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_TOUCH_TAP_KEY,
|
||||
@@ -384,14 +382,14 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(idCallOrder.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should listen to events only once', function() {
|
||||
it('should listen to events only once', () => {
|
||||
spyOn(EventListener, 'listen');
|
||||
ReactBrowserEventEmitter.listenTo(ON_CLICK_KEY, document);
|
||||
ReactBrowserEventEmitter.listenTo(ON_CLICK_KEY, document);
|
||||
expect(EventListener.listen.calls.count()).toBe(1);
|
||||
});
|
||||
|
||||
it('should work with event plugins without dependencies', function() {
|
||||
it('should work with event plugins without dependencies', () => {
|
||||
spyOn(EventListener, 'listen');
|
||||
|
||||
ReactBrowserEventEmitter.listenTo(ON_CLICK_KEY, document);
|
||||
@@ -399,7 +397,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(EventListener.listen.calls.argsFor(0)[1]).toBe('click');
|
||||
});
|
||||
|
||||
it('should work with event plugins with dependencies', function() {
|
||||
it('should work with event plugins with dependencies', () => {
|
||||
spyOn(EventListener, 'listen');
|
||||
spyOn(EventListener, 'capture');
|
||||
|
||||
@@ -424,7 +422,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('should bubble onTouchTap', function() {
|
||||
it('should bubble onTouchTap', () => {
|
||||
EventPluginHub.putListener(
|
||||
getInternal(CHILD),
|
||||
ON_TOUCH_TAP_KEY,
|
||||
@@ -454,7 +452,7 @@ describe('ReactBrowserEventEmitter', function() {
|
||||
expect(idCallOrder[2]).toBe(getInternal(GRANDPARENT));
|
||||
});
|
||||
|
||||
it('should not crash ensureScrollValueMonitoring when createEvent returns null', function() {
|
||||
it('should not crash ensureScrollValueMonitoring when createEvent returns null', () => {
|
||||
var originalCreateEvent = document.createEvent;
|
||||
document.createEvent = function() {
|
||||
return null;
|
||||
|
||||
@@ -16,7 +16,7 @@ var ReactDOM = require('ReactDOM');
|
||||
var ReactTestUtils = require('ReactTestUtils');
|
||||
var div = React.createFactory('div');
|
||||
|
||||
describe('ReactDOM', function() {
|
||||
describe('ReactDOM', () => {
|
||||
// TODO: uncomment this test once we can run in phantom, which
|
||||
// supports real submit events.
|
||||
/*
|
||||
@@ -46,13 +46,13 @@ describe('ReactDOM', function() {
|
||||
});
|
||||
*/
|
||||
|
||||
it('allows a DOM element to be used with a string', function() {
|
||||
it('allows a DOM element to be used with a string', () => {
|
||||
var element = React.createElement('div', {className: 'foo'});
|
||||
var instance = ReactTestUtils.renderIntoDocument(element);
|
||||
expect(ReactDOM.findDOMNode(instance).tagName).toBe('DIV');
|
||||
});
|
||||
|
||||
it('should allow children to be passed as an argument', function() {
|
||||
it('should allow children to be passed as an argument', () => {
|
||||
var argDiv = ReactTestUtils.renderIntoDocument(
|
||||
div(null, 'child')
|
||||
);
|
||||
@@ -60,7 +60,7 @@ describe('ReactDOM', function() {
|
||||
expect(argNode.innerHTML).toBe('child');
|
||||
});
|
||||
|
||||
it('should overwrite props.children with children argument', function() {
|
||||
it('should overwrite props.children with children argument', () => {
|
||||
var conflictDiv = ReactTestUtils.renderIntoDocument(
|
||||
div({children: 'fakechild'}, 'child')
|
||||
);
|
||||
@@ -72,7 +72,7 @@ describe('ReactDOM', function() {
|
||||
* We need to make sure that updates occur to the actual node that's in the
|
||||
* DOM, instead of a stale cache.
|
||||
*/
|
||||
it('should purge the DOM cache when removing nodes', function() {
|
||||
it('should purge the DOM cache when removing nodes', () => {
|
||||
var myDiv = ReactTestUtils.renderIntoDocument(
|
||||
<div>
|
||||
<div key="theDog" className="dog" />,
|
||||
@@ -111,14 +111,14 @@ describe('ReactDOM', function() {
|
||||
expect(dog.className).toBe('bigdog');
|
||||
});
|
||||
|
||||
it('allow React.DOM factories to be called without warnings', function() {
|
||||
it('allow React.DOM factories to be called without warnings', () => {
|
||||
spyOn(console, 'error');
|
||||
var element = React.DOM.div();
|
||||
expect(element.type).toBe('div');
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('throws in render() if the mount callback is not a function', function() {
|
||||
it('throws in render() if the mount callback is not a function', () => {
|
||||
function Foo() {
|
||||
this.a = 1;
|
||||
this.b = 2;
|
||||
@@ -147,7 +147,7 @@ describe('ReactDOM', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('throws in render() if the update callback is not a function', function() {
|
||||
it('throws in render() if the update callback is not a function', () => {
|
||||
function Foo() {
|
||||
this.a = 1;
|
||||
this.b = 2;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('ReactDOMComponentTree', function() {
|
||||
describe('ReactDOMComponentTree', () => {
|
||||
var React;
|
||||
var ReactDOM;
|
||||
var ReactDOMComponentTree;
|
||||
@@ -24,14 +24,14 @@ describe('ReactDOMComponentTree', function() {
|
||||
return ReactDOM.render(elt, container);
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
ReactDOMComponentTree = require('ReactDOMComponentTree');
|
||||
ReactDOMServer = require('ReactDOMServer');
|
||||
});
|
||||
|
||||
it('finds nodes for instances', function() {
|
||||
it('finds nodes for instances', () => {
|
||||
// This is a little hard to test directly. But refs rely on it -- so we
|
||||
// check that we can find a ref at arbitrary points in the tree, even if
|
||||
// other nodes don't have a ref.
|
||||
@@ -61,7 +61,7 @@ describe('ReactDOMComponentTree', function() {
|
||||
expect(renderAndGetRef('input')).toBe('INPUT');
|
||||
});
|
||||
|
||||
it('finds instances for nodes', function() {
|
||||
it('finds instances for nodes', () => {
|
||||
class Component extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
|
||||
@@ -11,12 +11,11 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('ReactDOMIDOperations', function() {
|
||||
describe('ReactDOMIDOperations', () => {
|
||||
var ReactDOMComponentTree = require('ReactDOMComponentTree');
|
||||
var ReactDOMIDOperations = require('ReactDOMIDOperations');
|
||||
var ReactMultiChildUpdateTypes = require('ReactMultiChildUpdateTypes');
|
||||
|
||||
it('should update innerHTML and preserve whitespace', function() {
|
||||
it('should update innerHTML and preserve whitespace', () => {
|
||||
var stubNode = document.createElement('div');
|
||||
var stubInstance = {_debugID: 1};
|
||||
ReactDOMComponentTree.precacheNode(stubInstance, stubNode);
|
||||
@@ -25,7 +24,7 @@ describe('ReactDOMIDOperations', function() {
|
||||
ReactDOMIDOperations.dangerouslyProcessChildrenUpdates(
|
||||
stubInstance,
|
||||
[{
|
||||
type: ReactMultiChildUpdateTypes.SET_MARKUP,
|
||||
type: 'SET_MARKUP',
|
||||
content: html,
|
||||
fromIndex: null,
|
||||
toIndex: null,
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
var React;
|
||||
var ReactDOMServer;
|
||||
|
||||
describe('ReactDOMSVG', function() {
|
||||
describe('ReactDOMSVG', () => {
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
React = require('React');
|
||||
ReactDOMServer = require('ReactDOMServer');
|
||||
});
|
||||
|
||||
it('creates initial namespaced markup', function() {
|
||||
it('creates initial namespaced markup', () => {
|
||||
var markup = ReactDOMServer.renderToString(
|
||||
<svg>
|
||||
<image xlinkHref="http://i.imgur.com/w7GCRPb.png" />
|
||||
|
||||
@@ -50,14 +50,14 @@ function renderParentIntoDocument() {
|
||||
return ReactTestUtils.renderIntoDocument(<ParentComponent />);
|
||||
}
|
||||
|
||||
describe('ReactDOMTreeTraversal', function() {
|
||||
describe('ReactDOMTreeTraversal', () => {
|
||||
var ReactDOMTreeTraversal;
|
||||
|
||||
var aggregatedArgs;
|
||||
function argAggregator(inst, isUp, arg) {
|
||||
function argAggregator(inst, phase, arg) {
|
||||
aggregatedArgs.push({
|
||||
node: ReactDOMComponentTree.getNodeFromInstance(inst),
|
||||
isUp: isUp,
|
||||
phase: phase,
|
||||
arg: arg,
|
||||
});
|
||||
}
|
||||
@@ -66,50 +66,50 @@ describe('ReactDOMTreeTraversal', function() {
|
||||
return ReactDOMComponentTree.getInstanceFromNode(node);
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
ReactDOMTreeTraversal = require('ReactDOMTreeTraversal');
|
||||
aggregatedArgs = [];
|
||||
});
|
||||
|
||||
describe('traverseTwoPhase', function() {
|
||||
it('should not traverse when traversing outside DOM', function() {
|
||||
describe('traverseTwoPhase', () => {
|
||||
it('should not traverse when traversing outside DOM', () => {
|
||||
var expectedAggregation = [];
|
||||
ReactDOMTreeTraversal.traverseTwoPhase(null, argAggregator, ARG);
|
||||
expect(aggregatedArgs).toEqual(expectedAggregation);
|
||||
});
|
||||
|
||||
it('should traverse two phase across component boundary', function() {
|
||||
it('should traverse two phase across component boundary', () => {
|
||||
var parent = renderParentIntoDocument();
|
||||
var target = getInst(parent.refs.P_P1_C1.refs.DIV_1);
|
||||
var expectedAggregation = [
|
||||
{node: parent.refs.P, isUp: false, arg: ARG},
|
||||
{node: parent.refs.P_P1, isUp: false, arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV, isUp: false, arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV_1, isUp: false, arg: ARG},
|
||||
{node: parent.refs.P, phase: 'captured', arg: ARG},
|
||||
{node: parent.refs.P_P1, phase: 'captured', arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV, phase: 'captured', arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV_1, phase: 'captured', arg: ARG},
|
||||
|
||||
{node: parent.refs.P_P1_C1.refs.DIV_1, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P_P1, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV_1, phase: 'bubbled', arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV, phase: 'bubbled', arg: ARG},
|
||||
{node: parent.refs.P_P1, phase: 'bubbled', arg: ARG},
|
||||
{node: parent.refs.P, phase: 'bubbled', arg: ARG},
|
||||
];
|
||||
ReactDOMTreeTraversal.traverseTwoPhase(target, argAggregator, ARG);
|
||||
expect(aggregatedArgs).toEqual(expectedAggregation);
|
||||
});
|
||||
|
||||
it('should traverse two phase at shallowest node', function() {
|
||||
it('should traverse two phase at shallowest node', () => {
|
||||
var parent = renderParentIntoDocument();
|
||||
var target = getInst(parent.refs.P);
|
||||
var expectedAggregation = [
|
||||
{node: parent.refs.P, isUp: false, arg: ARG},
|
||||
{node: parent.refs.P, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P, phase: 'captured', arg: ARG},
|
||||
{node: parent.refs.P, phase: 'bubbled', arg: ARG},
|
||||
];
|
||||
ReactDOMTreeTraversal.traverseTwoPhase(target, argAggregator, ARG);
|
||||
expect(aggregatedArgs).toEqual(expectedAggregation);
|
||||
});
|
||||
});
|
||||
|
||||
describe('traverseEnterLeave', function() {
|
||||
it('should not traverse when enter/leaving outside DOM', function() {
|
||||
describe('traverseEnterLeave', () => {
|
||||
it('should not traverse when enter/leaving outside DOM', () => {
|
||||
var target = null;
|
||||
var expectedAggregation = [];
|
||||
ReactDOMTreeTraversal.traverseEnterLeave(
|
||||
@@ -118,7 +118,7 @@ describe('ReactDOMTreeTraversal', function() {
|
||||
expect(aggregatedArgs).toEqual(expectedAggregation);
|
||||
});
|
||||
|
||||
it('should not traverse if enter/leave the same node', function() {
|
||||
it('should not traverse if enter/leave the same node', () => {
|
||||
var parent = renderParentIntoDocument();
|
||||
var leave = getInst(parent.refs.P_P1_C1.refs.DIV_1);
|
||||
var enter = getInst(parent.refs.P_P1_C1.refs.DIV_1);
|
||||
@@ -129,14 +129,14 @@ describe('ReactDOMTreeTraversal', function() {
|
||||
expect(aggregatedArgs).toEqual(expectedAggregation);
|
||||
});
|
||||
|
||||
it('should traverse enter/leave to sibling - avoids parent', function() {
|
||||
it('should traverse enter/leave to sibling - avoids parent', () => {
|
||||
var parent = renderParentIntoDocument();
|
||||
var leave = getInst(parent.refs.P_P1_C1.refs.DIV_1);
|
||||
var enter = getInst(parent.refs.P_P1_C1.refs.DIV_2);
|
||||
var expectedAggregation = [
|
||||
{node: parent.refs.P_P1_C1.refs.DIV_1, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV_1, phase: 'bubbled', arg: ARG},
|
||||
// enter/leave shouldn't fire anything on the parent
|
||||
{node: parent.refs.P_P1_C1.refs.DIV_2, isUp: false, arg: ARG2},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV_2, phase: 'captured', arg: ARG2},
|
||||
];
|
||||
ReactDOMTreeTraversal.traverseEnterLeave(
|
||||
leave, enter, argAggregator, ARG, ARG2
|
||||
@@ -144,12 +144,12 @@ describe('ReactDOMTreeTraversal', function() {
|
||||
expect(aggregatedArgs).toEqual(expectedAggregation);
|
||||
});
|
||||
|
||||
it('should traverse enter/leave to parent - avoids parent', function() {
|
||||
it('should traverse enter/leave to parent - avoids parent', () => {
|
||||
var parent = renderParentIntoDocument();
|
||||
var leave = getInst(parent.refs.P_P1_C1.refs.DIV_1);
|
||||
var enter = getInst(parent.refs.P_P1_C1.refs.DIV);
|
||||
var expectedAggregation = [
|
||||
{node: parent.refs.P_P1_C1.refs.DIV_1, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV_1, phase: 'bubbled', arg: ARG},
|
||||
];
|
||||
ReactDOMTreeTraversal.traverseEnterLeave(
|
||||
leave, enter, argAggregator, ARG, ARG2
|
||||
@@ -157,14 +157,14 @@ describe('ReactDOMTreeTraversal', function() {
|
||||
expect(aggregatedArgs).toEqual(expectedAggregation);
|
||||
});
|
||||
|
||||
it('should enter from the window', function() {
|
||||
it('should enter from the window', () => {
|
||||
var parent = renderParentIntoDocument();
|
||||
var leave = null; // From the window or outside of the React sandbox.
|
||||
var enter = getInst(parent.refs.P_P1_C1.refs.DIV);
|
||||
var expectedAggregation = [
|
||||
{node: parent.refs.P, isUp: false, arg: ARG2},
|
||||
{node: parent.refs.P_P1, isUp: false, arg: ARG2},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV, isUp: false, arg: ARG2},
|
||||
{node: parent.refs.P, phase: 'captured', arg: ARG2},
|
||||
{node: parent.refs.P_P1, phase: 'captured', arg: ARG2},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV, phase: 'captured', arg: ARG2},
|
||||
];
|
||||
ReactDOMTreeTraversal.traverseEnterLeave(
|
||||
leave, enter, argAggregator, ARG, ARG2
|
||||
@@ -172,12 +172,12 @@ describe('ReactDOMTreeTraversal', function() {
|
||||
expect(aggregatedArgs).toEqual(expectedAggregation);
|
||||
});
|
||||
|
||||
it('should enter from the window to the shallowest', function() {
|
||||
it('should enter from the window to the shallowest', () => {
|
||||
var parent = renderParentIntoDocument();
|
||||
var leave = null; // From the window or outside of the React sandbox.
|
||||
var enter = getInst(parent.refs.P);
|
||||
var expectedAggregation = [
|
||||
{node: parent.refs.P, isUp: false, arg: ARG2},
|
||||
{node: parent.refs.P, phase: 'captured', arg: ARG2},
|
||||
];
|
||||
ReactDOMTreeTraversal.traverseEnterLeave(
|
||||
leave, enter, argAggregator, ARG, ARG2
|
||||
@@ -185,14 +185,14 @@ describe('ReactDOMTreeTraversal', function() {
|
||||
expect(aggregatedArgs).toEqual(expectedAggregation);
|
||||
});
|
||||
|
||||
it('should leave to the window', function() {
|
||||
it('should leave to the window', () => {
|
||||
var parent = renderParentIntoDocument();
|
||||
var enter = null; // From the window or outside of the React sandbox.
|
||||
var leave = getInst(parent.refs.P_P1_C1.refs.DIV);
|
||||
var expectedAggregation = [
|
||||
{node: parent.refs.P_P1_C1.refs.DIV, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P_P1, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV, phase: 'bubbled', arg: ARG},
|
||||
{node: parent.refs.P_P1, phase: 'bubbled', arg: ARG},
|
||||
{node: parent.refs.P, phase: 'bubbled', arg: ARG},
|
||||
];
|
||||
ReactDOMTreeTraversal.traverseEnterLeave(
|
||||
leave, enter, argAggregator, ARG, ARG2
|
||||
@@ -200,14 +200,14 @@ describe('ReactDOMTreeTraversal', function() {
|
||||
expect(aggregatedArgs).toEqual(expectedAggregation);
|
||||
});
|
||||
|
||||
it('should leave to the window from the shallowest', function() {
|
||||
it('should leave to the window from the shallowest', () => {
|
||||
var parent = renderParentIntoDocument();
|
||||
var enter = null; // From the window or outside of the React sandbox.
|
||||
var leave = getInst(parent.refs.P_P1_C1.refs.DIV);
|
||||
var expectedAggregation = [
|
||||
{node: parent.refs.P_P1_C1.refs.DIV, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P_P1, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P, isUp: true, arg: ARG},
|
||||
{node: parent.refs.P_P1_C1.refs.DIV, phase: 'bubbled', arg: ARG},
|
||||
{node: parent.refs.P_P1, phase: 'bubbled', arg: ARG},
|
||||
{node: parent.refs.P, phase: 'bubbled', arg: ARG},
|
||||
];
|
||||
ReactDOMTreeTraversal.traverseEnterLeave(
|
||||
leave, enter, argAggregator, ARG, ARG2
|
||||
@@ -216,8 +216,8 @@ describe('ReactDOMTreeTraversal', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFirstCommonAncestor', function() {
|
||||
it('should determine the first common ancestor correctly', function() {
|
||||
describe('getFirstCommonAncestor', () => {
|
||||
it('should determine the first common ancestor correctly', () => {
|
||||
var parent = renderParentIntoDocument();
|
||||
var ancestors = [
|
||||
// Common ancestor with self is self.
|
||||
|
||||
@@ -15,8 +15,8 @@ var React;
|
||||
var ReactDOM;
|
||||
var ReactTestUtils;
|
||||
|
||||
describe('ReactEventIndependence', function() {
|
||||
beforeEach(function() {
|
||||
describe('ReactEventIndependence', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
|
||||
React = require('React');
|
||||
@@ -24,7 +24,7 @@ describe('ReactEventIndependence', function() {
|
||||
ReactTestUtils = require('ReactTestUtils');
|
||||
});
|
||||
|
||||
it('does not crash with other react inside', function() {
|
||||
it('does not crash with other react inside', () => {
|
||||
var clicks = 0;
|
||||
var div = ReactTestUtils.renderIntoDocument(
|
||||
<div
|
||||
@@ -38,7 +38,7 @@ describe('ReactEventIndependence', function() {
|
||||
expect(clicks).toBe(1);
|
||||
});
|
||||
|
||||
it('does not crash with other react outside', function() {
|
||||
it('does not crash with other react outside', () => {
|
||||
var clicks = 0;
|
||||
var outer = document.createElement('div');
|
||||
outer.setAttribute('data-reactid', '.z');
|
||||
@@ -50,7 +50,7 @@ describe('ReactEventIndependence', function() {
|
||||
expect(clicks).toBe(1);
|
||||
});
|
||||
|
||||
it('does not when event fired on unmounted tree', function() {
|
||||
it('does not when event fired on unmounted tree', () => {
|
||||
var clicks = 0;
|
||||
var container = document.createElement('div');
|
||||
var button = ReactDOM.render(
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
var EVENT_TARGET_PARAM = 1;
|
||||
|
||||
describe('ReactEventListener', function() {
|
||||
describe('ReactEventListener', () => {
|
||||
var React;
|
||||
var ReactDOM;
|
||||
var ReactDOMComponentTree;
|
||||
@@ -22,7 +22,7 @@ describe('ReactEventListener', function() {
|
||||
var ReactTestUtils;
|
||||
var handleTopLevel;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
React = require('React');
|
||||
ReactDOM = require('ReactDOM');
|
||||
@@ -34,7 +34,7 @@ describe('ReactEventListener', function() {
|
||||
ReactEventListener._handleTopLevel = handleTopLevel;
|
||||
});
|
||||
|
||||
it('should dispatch events from outside React tree', function() {
|
||||
it('should dispatch events from outside React tree', () => {
|
||||
var otherNode = document.createElement('h1');
|
||||
var component = ReactDOM.render(<div />, document.createElement('div'));
|
||||
expect(handleTopLevel.mock.calls.length).toBe(0);
|
||||
@@ -54,8 +54,8 @@ describe('ReactEventListener', function() {
|
||||
expect(handleTopLevel.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
describe('Propagation', function() {
|
||||
it('should propagate events one level down', function() {
|
||||
describe('Propagation', () => {
|
||||
it('should propagate events one level down', () => {
|
||||
var childContainer = document.createElement('div');
|
||||
var childControl = <div>Child</div>;
|
||||
var parentContainer = document.createElement('div');
|
||||
@@ -78,7 +78,7 @@ describe('ReactEventListener', function() {
|
||||
.toBe(ReactDOMComponentTree.getInstanceFromNode(parentControl));
|
||||
});
|
||||
|
||||
it('should propagate events two levels down', function() {
|
||||
it('should propagate events two levels down', () => {
|
||||
var childContainer = document.createElement('div');
|
||||
var childControl = <div>Child</div>;
|
||||
var parentContainer = document.createElement('div');
|
||||
@@ -108,7 +108,7 @@ describe('ReactEventListener', function() {
|
||||
.toBe(ReactDOMComponentTree.getInstanceFromNode(grandParentControl));
|
||||
});
|
||||
|
||||
it('should not get confused by disappearing elements', function() {
|
||||
it('should not get confused by disappearing elements', () => {
|
||||
var childContainer = document.createElement('div');
|
||||
var childControl = <div>Child</div>;
|
||||
var parentContainer = document.createElement('div');
|
||||
@@ -144,7 +144,7 @@ describe('ReactEventListener', function() {
|
||||
.toBe(ReactDOMComponentTree.getInstanceFromNode(parentControl));
|
||||
});
|
||||
|
||||
it('should batch between handlers from different roots', function() {
|
||||
it('should batch between handlers from different roots', () => {
|
||||
var childContainer = document.createElement('div');
|
||||
var parentContainer = document.createElement('div');
|
||||
var childControl = ReactDOM.render(
|
||||
@@ -183,7 +183,7 @@ describe('ReactEventListener', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not fire duplicate events for a React DOM tree', function() {
|
||||
it('should not fire duplicate events for a React DOM tree', () => {
|
||||
class Wrapper extends React.Component {
|
||||
getInner = () => {
|
||||
return this.refs.inner;
|
||||
|
||||
@@ -18,8 +18,8 @@ var ReactMount;
|
||||
var ReactTestUtils;
|
||||
var WebComponents;
|
||||
|
||||
describe('ReactMount', function() {
|
||||
beforeEach(function() {
|
||||
describe('ReactMount', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
|
||||
React = require('React');
|
||||
@@ -39,8 +39,8 @@ describe('ReactMount', function() {
|
||||
}
|
||||
});
|
||||
|
||||
describe('unmountComponentAtNode', function() {
|
||||
it('throws when given a non-node', function() {
|
||||
describe('unmountComponentAtNode', () => {
|
||||
it('throws when given a non-node', () => {
|
||||
var nodeArray = document.getElementsByTagName('div');
|
||||
expect(function() {
|
||||
ReactDOM.unmountComponentAtNode(nodeArray);
|
||||
@@ -50,7 +50,7 @@ describe('ReactMount', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('throws when given a string', function() {
|
||||
it('throws when given a string', () => {
|
||||
expect(function() {
|
||||
ReactTestUtils.renderIntoDocument('div');
|
||||
}).toThrowError(
|
||||
@@ -59,7 +59,7 @@ describe('ReactMount', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('throws when given a factory', function() {
|
||||
it('throws when given a factory', () => {
|
||||
class Component extends React.Component {
|
||||
render() {
|
||||
return <div />;
|
||||
@@ -74,7 +74,7 @@ describe('ReactMount', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should render different components in same root', function() {
|
||||
it('should render different components in same root', () => {
|
||||
var container = document.createElement('container');
|
||||
document.body.appendChild(container);
|
||||
|
||||
@@ -85,7 +85,7 @@ describe('ReactMount', function() {
|
||||
expect(container.firstChild.nodeName).toBe('SPAN');
|
||||
});
|
||||
|
||||
it('should unmount and remount if the key changes', function() {
|
||||
it('should unmount and remount if the key changes', () => {
|
||||
var container = document.createElement('container');
|
||||
|
||||
var mockMount = jest.fn();
|
||||
@@ -120,7 +120,7 @@ describe('ReactMount', function() {
|
||||
expect(mockUnmount.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should reuse markup if rendering to the same target twice', function() {
|
||||
it('should reuse markup if rendering to the same target twice', () => {
|
||||
var container = document.createElement('container');
|
||||
var instance1 = ReactDOM.render(<div />, container);
|
||||
var instance2 = ReactDOM.render(<div />, container);
|
||||
@@ -128,7 +128,7 @@ describe('ReactMount', function() {
|
||||
expect(instance1 === instance2).toBe(true);
|
||||
});
|
||||
|
||||
it('should warn if mounting into dirty rendered markup', function() {
|
||||
it('should warn if mounting into dirty rendered markup', () => {
|
||||
var container = document.createElement('container');
|
||||
container.innerHTML = ReactDOMServer.renderToString(<div />) + ' ';
|
||||
|
||||
@@ -142,7 +142,7 @@ describe('ReactMount', function() {
|
||||
expect(console.error.calls.count()).toBe(2);
|
||||
});
|
||||
|
||||
it('should not warn if mounting into non-empty node', function() {
|
||||
it('should not warn if mounting into non-empty node', () => {
|
||||
var container = document.createElement('container');
|
||||
container.innerHTML = '<div></div>';
|
||||
|
||||
@@ -151,7 +151,7 @@ describe('ReactMount', function() {
|
||||
expect(console.error.calls.count()).toBe(0);
|
||||
});
|
||||
|
||||
it('should warn when mounting into document.body', function() {
|
||||
it('should warn when mounting into document.body', () => {
|
||||
var iFrame = document.createElement('iframe');
|
||||
document.body.appendChild(iFrame);
|
||||
spyOn(console, 'error');
|
||||
@@ -164,7 +164,7 @@ describe('ReactMount', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should account for escaping on a checksum mismatch', function() {
|
||||
it('should account for escaping on a checksum mismatch', () => {
|
||||
var div = document.createElement('div');
|
||||
var markup = ReactDOMServer.renderToString(
|
||||
<div>This markup contains an nbsp entity: server text</div>);
|
||||
@@ -183,7 +183,7 @@ describe('ReactMount', function() {
|
||||
});
|
||||
|
||||
if (WebComponents !== undefined) {
|
||||
it('should allow mounting/unmounting to document fragment container', function() {
|
||||
it('should allow mounting/unmounting to document fragment container', () => {
|
||||
var shadowRoot;
|
||||
var proto = Object.create(HTMLElement.prototype, {
|
||||
createdCallback: {
|
||||
@@ -205,7 +205,7 @@ describe('ReactMount', function() {
|
||||
});
|
||||
}
|
||||
|
||||
it('should warn if render removes React-rendered children', function() {
|
||||
it('should warn if render removes React-rendered children', () => {
|
||||
var container = document.createElement('container');
|
||||
|
||||
class Component extends React.Component {
|
||||
@@ -229,7 +229,7 @@ describe('ReactMount', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn if the unmounted node was rendered by another copy of React', function() {
|
||||
it('should warn if the unmounted node was rendered by another copy of React', () => {
|
||||
jest.resetModuleRegistry();
|
||||
var ReactDOMOther = require('ReactDOM');
|
||||
var container = document.createElement('div');
|
||||
@@ -257,7 +257,7 @@ describe('ReactMount', function() {
|
||||
expect(console.error.calls.count()).toBe(1);
|
||||
});
|
||||
|
||||
it('passes the correct callback context', function() {
|
||||
it('passes the correct callback context', () => {
|
||||
var container = document.createElement('div');
|
||||
var calls = 0;
|
||||
|
||||
@@ -297,7 +297,7 @@ describe('ReactMount', function() {
|
||||
expect(calls).toBe(5);
|
||||
});
|
||||
|
||||
it('tracks root instances', function() {
|
||||
it('tracks root instances', () => {
|
||||
// Used by devtools.
|
||||
expect(Object.keys(ReactMount._instancesByReactRootID).length).toBe(0);
|
||||
ReactTestUtils.renderIntoDocument(<span />);
|
||||
@@ -309,7 +309,7 @@ describe('ReactMount', function() {
|
||||
expect(Object.keys(ReactMount._instancesByReactRootID).length).toBe(1);
|
||||
});
|
||||
|
||||
it('marks top-level mounts', function() {
|
||||
it('marks top-level mounts', () => {
|
||||
var ReactFeatureFlags = require('ReactFeatureFlags');
|
||||
|
||||
class Foo extends React.Component {
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
var React = require('React');
|
||||
var ReactDOM = require('ReactDOM');
|
||||
|
||||
describe('ReactMount', function() {
|
||||
it('should destroy a react root upon request', function() {
|
||||
describe('ReactMount', () => {
|
||||
it('should destroy a react root upon request', () => {
|
||||
var mainContainerDiv = document.createElement('div');
|
||||
document.body.appendChild(mainContainerDiv);
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('ReactMount', function() {
|
||||
expect(secondRootDiv.firstChild).toBeNull();
|
||||
});
|
||||
|
||||
it('should warn when unmounting a non-container root node', function() {
|
||||
it('should warn when unmounting a non-container root node', () => {
|
||||
var mainContainerDiv = document.createElement('div');
|
||||
|
||||
var component =
|
||||
@@ -62,7 +62,7 @@ describe('ReactMount', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should warn when unmounting a non-container, non-root node', function() {
|
||||
it('should warn when unmounting a non-container, non-root node', () => {
|
||||
var mainContainerDiv = document.createElement('div');
|
||||
|
||||
var component =
|
||||
|
||||
@@ -26,8 +26,8 @@ var UNMOUNT_INVARIANT_MESSAGE =
|
||||
'efficiently. To fix this, have a single top-level component that ' +
|
||||
'never unmounts render these elements.';
|
||||
|
||||
describe('rendering React components at document', function() {
|
||||
beforeEach(function() {
|
||||
describe('rendering React components at document', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
|
||||
React = require('React');
|
||||
@@ -38,7 +38,7 @@ describe('rendering React components at document', function() {
|
||||
testDocument = getTestDocument();
|
||||
});
|
||||
|
||||
it('should be able to adopt server markup', function() {
|
||||
it('should be able to adopt server markup', () => {
|
||||
expect(testDocument).not.toBeUndefined();
|
||||
|
||||
class Root extends React.Component {
|
||||
@@ -69,7 +69,7 @@ describe('rendering React components at document', function() {
|
||||
expect(body).toBe(testDocument.body);
|
||||
});
|
||||
|
||||
it('should not be able to unmount component from document node', function() {
|
||||
it('should not be able to unmount component from document node', () => {
|
||||
expect(testDocument).not.toBeUndefined();
|
||||
|
||||
class Root extends React.Component {
|
||||
@@ -99,7 +99,7 @@ describe('rendering React components at document', function() {
|
||||
expect(testDocument.body.innerHTML).toBe('Hello world');
|
||||
});
|
||||
|
||||
it('should not be able to switch root constructors', function() {
|
||||
it('should not be able to switch root constructors', () => {
|
||||
expect(testDocument).not.toBeUndefined();
|
||||
|
||||
class Component extends React.Component {
|
||||
@@ -147,7 +147,7 @@ describe('rendering React components at document', function() {
|
||||
expect(testDocument.body.innerHTML).toBe('Hello world');
|
||||
});
|
||||
|
||||
it('should be able to mount into document', function() {
|
||||
it('should be able to mount into document', () => {
|
||||
expect(testDocument).not.toBeUndefined();
|
||||
|
||||
class Component extends React.Component {
|
||||
@@ -175,7 +175,7 @@ describe('rendering React components at document', function() {
|
||||
expect(testDocument.body.innerHTML).toBe('Hello world');
|
||||
});
|
||||
|
||||
it('should give helpful errors on state desync', function() {
|
||||
it('should give helpful errors on state desync', () => {
|
||||
expect(testDocument).not.toBeUndefined();
|
||||
|
||||
class Component extends React.Component {
|
||||
@@ -215,7 +215,7 @@ describe('rendering React components at document', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw on full document render w/ no markup', function() {
|
||||
it('should throw on full document render w/ no markup', () => {
|
||||
expect(testDocument).not.toBeUndefined();
|
||||
|
||||
var container = testDocument;
|
||||
@@ -245,7 +245,7 @@ describe('rendering React components at document', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('supports findDOMNode on full-page components', function() {
|
||||
it('supports findDOMNode on full-page components', () => {
|
||||
var tree =
|
||||
<html>
|
||||
<head>
|
||||
|
||||
@@ -15,12 +15,12 @@ var React = require('React');
|
||||
var ReactDOM = require('ReactDOM');
|
||||
var ReactTestUtils = require('ReactTestUtils');
|
||||
|
||||
describe('findDOMNode', function() {
|
||||
it('findDOMNode should return null if passed null', function() {
|
||||
describe('findDOMNode', () => {
|
||||
it('findDOMNode should return null if passed null', () => {
|
||||
expect(ReactDOM.findDOMNode(null)).toBe(null);
|
||||
});
|
||||
|
||||
it('findDOMNode should find dom element', function() {
|
||||
it('findDOMNode should find dom element', () => {
|
||||
class MyNode extends React.Component {
|
||||
render() {
|
||||
return <div><span>Noise</span></div>;
|
||||
@@ -34,7 +34,7 @@ describe('findDOMNode', function() {
|
||||
expect(mySameDiv).toBe(myDiv);
|
||||
});
|
||||
|
||||
it('findDOMNode should reject random objects', function() {
|
||||
it('findDOMNode should reject random objects', () => {
|
||||
expect(function() {
|
||||
ReactDOM.findDOMNode({foo: 'bar'});
|
||||
}).toThrowError(
|
||||
@@ -42,7 +42,7 @@ describe('findDOMNode', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('findDOMNode should reject unmounted objects with render func', function() {
|
||||
it('findDOMNode should reject unmounted objects with render func', () => {
|
||||
class Foo extends React.Component {
|
||||
render() {
|
||||
return <div />;
|
||||
@@ -58,7 +58,7 @@ describe('findDOMNode', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('findDOMNode should not throw an error when called within a component that is not mounted', function() {
|
||||
it('findDOMNode should not throw an error when called within a component that is not mounted', () => {
|
||||
class Bar extends React.Component {
|
||||
componentWillMount() {
|
||||
expect(ReactDOM.findDOMNode(this)).toBeNull();
|
||||
|
||||
Loaded 100 of 277 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user