React 12.2 から React 13.3 にアップグレードすると、テスト スイートで次のエラーが発生します。
エラー: 不変違反: unmountComponentAtNode(...): ターゲット コンテナーは DOM 要素ではありません。
このブログ投稿を使用して、Jasmine を使用してコードをテストしています。エラーは次のコードで発生します。
describe("A component", function() {
var instance;
var container = document.createElement("div");
afterEach(function() {
if (instance && instance.isMounted()) {
// Only components with a parent will be unmounted
React.unmountComponentAtNode(instance.getDOMNode().parent);
}
});
...rest of test suite...
// the instances of renderIntoDocument that cause the failure look like the below
it("Causes my test suite to fail.", function() {
instance = TestUtils.renderIntoDocument(<MyReactElement/>);
});
)};
私はそれgetDOMNode()
が非推奨であることを知っていますが、それがエラーの原因ではありません。
を検査するinstance.getDOMNode()
と、指定されたインスタンスが返されますが、エラーが発生した場合、instance.getDOMNode().parent
は未定義です。React.unmountComponentAtNode
この未定義の変数を呼び出すと、エラーが発生します。
このような回答は、ある種の競合状態が発生していることを示唆していますが、それが私のテスト スイートにどのように適用されるかはわかりません。助けてくれてありがとう!