【问题标题】:unit testing using jasmine marbles使用茉莉弹珠进行单元测试
【发布时间】:2021-09-14 05:19:06
【问题描述】:

我正在尝试使用 jasmine-marbles 进行简单测试,但出现错误

这是我的测试代码:

describe('MarbleTestingComponent', () => {
  it('should test marble syntax', () => {
    const provided = search('e');
    const expected = cold('(e|)', {e: 'e'});
    console.log(expected, provided);
    expect(provided).toBeObservable(expected);
  })   

});

这是我得到的错误:

Error: 
            Expected: (e|),
            Received: (?|),
            
            Expected:
            [{"frame":0,"notification":{"kind":"N","value":"e","hasValue":true}},{"frame":0,"notification":{"kind":"C","hasValue":false}}]
            
            Received:
            [{"frame":0,"notification":{"kind":"N","value":"e"}},{"frame":0,"notification":{"kind":"C"}}],

如果我使用 jest 框架,上面的代码可以工作,但我想让它与 Angular 设置附带的默认测试框架一起工作

感谢您对解决此错误的任何帮助 谢谢

【问题讨论】:

    标签: angular rxjs jasmine-marbles


    【解决方案1】:

    我不知道是否可以帮助你,但我在测试效果时遇到了同样的问题,我使用https://ngrx.io/guide/effects/testing#with-testscheduler 修复了它。我认为 jasmine-marbles 的最新版本与 rxjs 不一致。

    希望对你有帮助。

    【讨论】:

    • 是的,它似乎与最新版本的 RxJS 不一致。请参阅下面的答案。降级jasmine-marbles 版本后,我的问题得到了解决
    • 很高兴知道,其实如果你看到包的yarn.lock,就可以看到是使用jasmine-marbles@~0.6.0: version "0.6.0"
    【解决方案2】:

    尝试检查 jasmine-marbles 版本。

    我在使用 "jasmine-marbles": "^0.9.0" 和 "rxjs": "^6.6.7" 时遇到了同样的问题。

    降级到“jasmine-marbles”:“^0.8.0”解决了这个问题。

    在此处查看支持的版本:https://github.com/synapse-wireless-labs/jasmine-marbles#readme

    【讨论】:

      猜你喜欢
      • 2019-02-04
      • 1970-01-01
      • 2023-03-15
      • 2020-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-27
      相关资源
      最近更新 更多