小编Mar*_*del的帖子

单元测试和角度未处理的 Promise 拒绝

我目前在使用带有承诺的茉莉花测试时遇到问题。

错误是“未处理的承诺拒绝:”这意味着我的承诺没有正确处理catch()then()我想。

这是我的测试:

it('tests the openRepo function with changed and invalid path', (done) => {
    const OldPath = '/old';
    const NewPath = '/invalid';
    const ProjectModalBoolean = true;
    component.path = OldPath;
    component.openFolder = NewPath;
    component.projectModalLoading = ProjectModalBoolean;
    component.openRepo().then(() => {
      expect(component.openFolder).toBe('');
      expect(component.projectModalLoading).toBeFalsy();
      done();
    });
  });
Run Code Online (Sandbox Code Playgroud)

在函数中openRepo我有以下代码:

return this.gitService.setPath(this.openFolder)
          .then((data) => {
            this.projectModalLoading = false;
            this.projectModalVisible = false;
            this.openFolder = '';
            this.toastr.info(data.message, data.title);
          })
          .catch((data) => {
            this.projectModalLoading = false;
            this.openFolder = '';
            this.toastr.error(data.message, data.title);
          }); …
Run Code Online (Sandbox Code Playgroud)

jasmine angular

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

根据对象数组生成树

我想生成以下形式的树:

[
  {
  folder: 'src',
  children: [
    {
      folder: 'app',
      children: [
        { file: 'app.module.ts', status: 'M' },
        {
          folder: 'components',
          children: [
            { 
              folder: 'accordion',
              children: [
                { file: 'accordion.components.scss', status: 'M'}
              ]
            },
            {
              folder: 'file-diff-commit',
              children: [
                { file: 'file-diff-commit.component.html', status: 'A' },
                { file: 'file-diff-commit.component.ts', status: 'A' }
              ]
            }
          ]
        },
        {
          folder: 'models',
          children: [
            { file: 'MockGitService.ts' , status: 'M' },
            { file: 'MockLeftPanelService.ts', status: 'M'} 
          ]
        }
      ]
    },
    {
      folder: 'assets' …
Run Code Online (Sandbox Code Playgroud)

javascript tree angular

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

了解在提交中创建、修改或删除了哪些文件

我目前正在尝试显示有关我的应用程序中特定提交的信息。

我想知道这些文件是否在本次提交中创建、修改或删除,但如果我使用git show,我得到的信息将是删除或添加的行数。

git

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

标签 统计

angular ×2

git ×1

jasmine ×1

javascript ×1

tree ×1