首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Aurelia-testing:未能在“”Node“”上执行“”replaceChild“”:参数1不是“”Node“”类型

Aurelia-testing:未能在“”Node“”上执行“”replaceChild“”:参数1不是“”Node“”类型
EN

Stack Overflow用户
提问于 2020-07-02 22:51:56
回答 1查看 107关注 0票数 0

我第一次使用aurelia-testing包来测试我的代码。

我似乎遵循the docs来设置我的测试,如下所示:

代码语言:javascript
复制
describe('Contextual Menu HTML View test suite', function () {
  let component: ComponentTester;

  beforeEach(function () {
    component = StageComponent
      .withResources('../../src/components/modal/contextual-menu')
      .inView('<contextual-menu is-active.two-way="activateMenu"></contextual-menu>')
      .boundTo({ activateMenu: false });
  });

  it('should not add the is-active class to the root element', async function () {
    await component.create(bootstrap);
    const rootElement = await waitForDocumentElement('.qa-contextual-menu');
    expect(rootElement.classList.contains('is-active')).toBe(false);
  });

  afterEach(function () {
    component.dispose();
  });
});

我试着用bind代替two-way,但也失败了。我用document.querySelectorwaitForDocumentElement都试过了,两种情况都失败了,但不管怎样,我假设错误来自于前面。

我收到一个错误,但我不确定原因。你能在轨道上找出以下问题的根本原因:

代码语言:javascript
复制
TypeError: Failed to execute 'replaceChild' on 'Node': parameter 1 is not of type 'Node'.
  at Object.convert (/Users/lemoustachiste/work/lm-frontend/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/generated/Node.js:573:11)
at HTMLDivElement.replaceChild (/Users/lemoustachiste/work/lm-frontend/node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/living/generated/Node.js:292:31)
at NodeJsDom.replaceNode (/Users/lemoustachiste/work/lm-frontend/node_modules/aurelia-pal-nodejs/dist/nodejs-dom.js:95:29)
at makeElementIntoAnchor (/Users/lemoustachiste/work/lm-frontend/node_modules/aurelia-templating/dist/commonjs/aurelia-templating.js:2432:19)
at applyInstructions (/Users/lemoustachiste/work/lm-frontend/node_modules/aurelia-templating/dist/commonjs/aurelia-templating.js:2479:17)
at ViewFactory.create (/Users/lemoustachiste/work/lm-frontend/node_modules/aurelia-templating/dist/commonjs/aurelia-templating.js:2707:7)
at TemplatingEngine.enhance (/Users/lemoustachiste/work/lm-frontend/node_modules/aurelia-templating/dist/commonjs/aurelia-templating.js:5290:24)
at /Users/lemoustachiste/work/lm-frontend/node_modules/aurelia-framework/dist/commonjs/aurelia-framework.js:176:28
at new Promise (<anonymous>)
at Aurelia.enhance (/Users/lemoustachiste/work/lm-frontend/node_modules/aurelia-framework/dist/commonjs/aurelia-framework.js:174:12)

非常感谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-09 01:11:22

我不是一个jest用户。所以我简单地使用了来自aurelia-cli (au new jest-skeleton --unattended --select typescript,jest,vscode)的脚手架TS jest框架应用程序。并发现这是有效的。

您的jest.config.js中似乎缺少以下配置。

代码语言:javascript
复制
testEnvironment: "node",

仅仅添加了这些之后,测试就开始工作了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62699108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档