在柏树和打字稿中设置Tinymce编辑器的内容
我正在使用Typescript构建React JS应用程序。我正在使用柏树为我的应用程序编写集成测试。我还使用打字稿编写柏树测试。我现在正在尝试在柏树测试中设置小型MCE编辑器的内容。我正在尝试使用此库, https://github.com/foreachos/cypress/cypress-tinymce 。但是我不能将该库与打字稿一起使用,因为它仅适用于JavaScript。因此,我查看了设置编辑器值的基础代码。如下。
Cypress.Commands.add('setTinyMceContent', (tinyMceId, content) => {
cy.window().then((win) => {
const editor = win.tinymce.editors[tinyMceId];
editor.setContent(content);
});
});
因此,我尝试在我的支持/index.js文件中创建该命令的打字稿版本如下。
Cypress.Commands.add('setTinyMceContent', (tinyMceId: string, content: any) => {
cy.window().then((win) => {
const editor = win.tinymce.editors[tinyMceId];
editor.setContent(content);
})
})
但是它抱怨如下。
Property 'tinymce' does not exist on type 'AUTWindow'.
我该如何修复?
I am building a React Js application using Typescript. I am writing integration tests for my application using Cypress. I am also using Typescript for writing Cypress tests. I am now trying to set the content of the tiny MCE editor in the Cypress test. I am trying to use this library, https://github.com/ForeachOS/cypress-tinymce. But I cannot use that library with TypeScript as it is only for JavaScript. So I had a look at the underlying code that sets the value of the editor. It is as follow.
Cypress.Commands.add('setTinyMceContent', (tinyMceId, content) => {
cy.window().then((win) => {
const editor = win.tinymce.editors[tinyMceId];
editor.setContent(content);
});
});
So I tried to create the TypeScript version of that command in my support/index.js file as follow.
Cypress.Commands.add('setTinyMceContent', (tinyMceId: string, content: any) => {
cy.window().then((win) => {
const editor = win.tinymce.editors[tinyMceId];
editor.setContent(content);
})
})
But it is complaining as follow.
Property 'tinymce' does not exist on type 'AUTWindow'.
How can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在
cypress.d.ts
中查看autwindow
及其下方的声明,用户定义的属性
您可以添加您自己的属性通过声明合并。
在您的
/cypress/support/e2e.d.t.ts
(cypress v10)或/cypress/support/support/index.d.t.ts
(cypress v9) =“ https://www.npmjs.com/package/@types/tinymce” rel =“ noreferrer”>@type/tinymce ,这可能很有用。
If you take a look in
cypress.d.ts
there's a declaration forAUTWindow
and underneath that is ApplicationWindow for user-defined properties
You can add your own properties via declaration merging.
In your
/cypress/support/e2e.d.ts
(Cypress v10) or/cypress/support/index.d.ts
(Cypress v9)There's also @types/tinymce which may be useful down the line.
谢谢@johnydevnull,但是就我而言,我必须进行一些更改,
我还准备了命令以阅读柏树步骤的值
,然后您可以检查值:
Thanks @JohnyDevNull, but in my case i had to do some changes
Also i prepared command for reading a value
in cypress steps then you can check value with:
在这里,一个强大的解决方案可以处理动态编辑器ID:
Here a robust solution wich handles the dynamic editor ID's: