- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
不确定为什么我的简单 Main.test 文件中会出现此错误。
export class Main extends Component {
constructor(props) {
super(props);
this.state = {
location: splitString(props.location.pathname, '/dashboard/')
}
if (R.isEmpty(props.view)) {
isViewServices(this.state.location)
? this.props.gotoServicesView()
: this.props.gotoUsersView()
}
}
import React from 'react'
import * as enzyme from 'enzyme'
import toJson from 'enzyme-to-json'
import { Main } from './Main'
import Sidebar from '../../components/Common/sidebar'
const main = enzyme.shallow(<Main />);
describe('<Main /> component', () => {
it('should render', () => {
const tree = toJson(main);
expect(tree).toMatchSnapshot();
});
it('contains the Sidebar', () => {
expect(main.find(Sidebar).length).toBe(1);
});
});
有没有办法模拟“路径名”?
最佳答案
看来您可能有一些错误,其中一个是您在测试中没有传递任何 Prop 。
另一个来自您在构造函数中访问 this.props
。
请参阅您的 if
语句,但我会在此处明确修复
if (R.isEmpty(props.view)) {
isViewServices(this.state.location)
? props.gotoServicesView()
: props.gotoUsersView()
}
在主测试中
const location = { pathname: '/dashboard/' };
const main = enzyme.shallow(<Main location={ location }/>);
关于javascript - React Jest 测试无法读取未定义的属性 'pathname',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45287894/
我正在尝试优化我的 JavaScript 代码以提高速度。 我需要经常访问 document 对象的某些属性,例如 document.location.pathname ,甚至更糟糕的是 docume
我想获取目录中除隐藏文件(名称以点开头的文件)之外的所有文件: @files = Pathname.new('.').children.select do |file| file.basename
我在使用 opendir() 时收到了一些奇怪的结果: int dtw(char *path) { struct stat statbuf; ... else if (S_IS
我刚刚开始学习 jquery,我想知道我做得是否正确。这是我的代码 var images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg','6.jpg'
我正在尝试在 Angularjs 中编写内联条件语句。基本上,我想做到这一点,以便当单击页面上的选项卡时,页面会更新为 aria-current="page"。我要执行此操作的方法是检查选项卡 anc
所以我的页面中有这段代码:一个非常简单但有效的脚本,可以将它翻译成多种语言。 // preparing language file var aLangKeys=new Array(); aLangKe
我正在尝试重定向到相对网址,如下所示 setTimeout(window.location.pathname = '/help/fusion/index.php#3', 500); 但是#在传递给wi
我正在使用 Pathname.glob 来匹配文件。 Pathname.glob("**/*") 只匹配非隐藏文件 Pathname.glob("**/.*") 只匹配隐藏文件 有什么办法可以同时满足
我正在做一个项目,我有一个动态确定的挂载点,并提供了一组绝对路径来处理目标卷。由于这些文件尚不存在,我使用 Pathname 类来处理文件名操作。但是,在连接具有相同根的路径时,Pathname 似乎
考虑以下 Javascript: var anchors = document.getElementsByTagName('a'); for(var i=0; i < anchors.length;
我目前正在使用以下代码来定位单个页面,例如 http://my-website.com/about/ if (document.location.pathname == "/about/")
假设我访问 Javascript 的 window.pathname 并获取 /you/are/here。 是否可以构造一个正则表达式,从头开始逐步匹配路径的每个部分?换句话说,my_regex.ex
我正在使用 var url = location.pathname.split("/") 来分割 URL。 结果的第一个和最后一个元素始终为空。谁能解释一下为什么会这样? 谢谢。 最佳答案 因为路径以
我有一个类似于此的网址: www.mysite.com/products/ 我用它来测试路径名: if (/\/products\//.test(window.location)) { _gaq.pu
我想在主域和 /the/rest/of/url 之间的 URL 中添加哈希值。 显然,我做得不对。 我用过: window.location.hash = location.pathname; 希望
我希望 jQuery 提取 url,然后解析它以查找机场。如果找到机场,我想在列表项中添加一个类 包含 html“机场”的标签。 这是我目前所拥有的: JQuery path_name=locati
我正在为应用程序设置身份验证。在我发出登录后请求后,将发送一个 JSON Web token 作为响应。我可以通过 Ajax 将其附加到 header 。问题是在登录后使用 window.locati
不确定为什么我的简单 Main.test 文件中会出现此错误。 Main.js 的构造函数 export class Main extends Component { constructor(
我正在尝试使用 location.pathname.indexOf 让条件 jQuery 在我网站的某些页面上工作。 这个有效: if (location.pathname.indexOf("/exa
我更新了我的项目的 Ruby 和 Rails 版本。 ruby 2.2.3 –> 2.5.1 rails 4.1.8 –> 5.1.7 现在,当我启动服务器时,出现此错误: F, [2020-02-0
我是一名优秀的程序员,十分优秀!