小编Mar*_*ano的帖子

如何使 Vue3 测试工具与 teleport 一起使用

我有一个使用 teleport to 的组件,测试 html 似乎没有按预期工作。我找不到有关此特定用途的任何文档。这是我的测试:

describe('MetaHead', () => {
  it('dynamic metadata tags contain custom text', () => {

    let title = 'My Page';
    let description = 'Some description about my page';
    // This component uses Vue3's teleport to tag <head>
    // we must modify wrapper to contain such tag
    document.body.innerHTML = `
      <head>
        <div id="app"></div>
      </head>
    `

    const wrapper = mount(MetaHead, {
      attachTo: document.getElementById('app'),
      props: { 
        title,
        description
      },
      global:{
        mocks: {
          $route:{fullPath: 'full/path'}
        } 
      }
    })
    expect(wrapper.html()).toContain(title)
    expect(wrapper.html()).toContain(description) …
Run Code Online (Sandbox Code Playgroud)

vue-test-utils vuejs3 vue-teleport

6
推荐指数
1
解决办法
3180
查看次数

如何在包含字符串的任何匹配项中搜索对象数组?

我有一个包含以下模式的记录数组:

apis = [{
  info: {
    title: 'some title"
  }
}]
Run Code Online (Sandbox Code Playgroud)

我需要返回用户输入是记录标题的所有记录.

我尝试使用Lodash这样的东西,但"title"总是一个字母.

this.searchResults = this.apis.filter(function(item){
    return _.some(item.info.title, function (title) {
        return _.includes(title, query);
    });
});
Run Code Online (Sandbox Code Playgroud)

javascript arrays lodash

1
推荐指数
1
解决办法
2269
查看次数