我们可以模拟打印模式(媒体查询打印)进行单元测试吗? [英] can we emulate print mode (media query print) for unit testing?

查看:63
本文介绍了我们可以模拟打印模式(媒体查询打印)进行单元测试吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以模拟单元测试的打印模式(媒体查询打印)吗?
(Ract,酶,jest)我尝试:

can we emulate print mode (media query print) for unit testing? (Ract, enzyme, jest) i try:

window.matchMedia('print')

但它对我不起作用,未应用样式媒体打印;

but it does not work for me, style media print not applied;

推荐答案

我使用iframe进行打印并为此添加了一些param到url。
我们可以使用thit param测试打印:

I use iframe for printing and added some param to url for that. We can test printing using thit param:

window.location.hash = '?printMode=true'; // my variant

在该运行组件之后,让我们尝试编写测试。

after that run component and lets try to write tests.

这篇关于我们可以模拟打印模式(媒体查询打印)进行单元测试吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆