querySelectorAll()是否接受('div.element:first')这种类型的参数?我需要在VanillaJS中转换下面的jQuery方法
jQUery:
$li = $(this)
$li.find('div.element:first')
Run Code Online (Sandbox Code Playgroud)
香草 :
var li = event.target;
li.querySelectorAll('div.element:first');
Run Code Online (Sandbox Code Playgroud)
但是Vanilla脚本与jQuery的工作方式不同.有人请建议任何更好的解决方案
我正在尝试为此功能添加单元测试:
var advance = function (des, source) {
for (var p in source) {
if (source.hasOwnProperty(p)) {
des[p] = source[p];
}
}
return des;
};
Run Code Online (Sandbox Code Playgroud)
我们如何检查hasOwnProperty()茉莉花中的方法?
编辑: 可能的解决方案
var des;
var source;
beforeEach(function () {
des = {};
source = {
p: 'value',
p1: 'value1'
};
});
beforeAll(function () {
advance(des, source);
});
it('should has a property with the name of the argument', function () {
expect(source).toEqual(jasmine.objectContaining({
p: 'value'
}));
expect(source).not.toEqual(jasmine.objectContaining({
p2: 'value2'
}));
});
Run Code Online (Sandbox Code Playgroud)
有人,请提出任何更好的解决方案。