【问题标题】:Jasmine tests always failing in RxJS 7 when using toBeObservable()使用 toBeObservable() 时,Jasmine 测试在 RxJS 7 中总是失败
【发布时间】:2022-01-16 10:32:18
【问题描述】:

我已经更新了我的依赖项,现在遇到了这个错误消息:

DEPRECATION: The matcher factory for "toBeObservable" accepts custom equality testers, but this parameter will no longer be passed in a future release. See <https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0#matchers-cet> for details.

Error: Expected $[0].notification to be a kind of Object, but was Notification({ kind: 'N', value: true, error: undefined, hasValue: true }).
            at <Jasmine>
            at toBeObservableComparer (node_modules/jasmine-marbles/es6/index.js:80:1)
            at <Jasmine>

测试很简单:

const expected = cold('a', {a: true});
expect(new BehaviorSubject(true)).toBeObservable(expected);

它可能与弃用通知有关,但我只是使用最新版本的jasmine-marbles 包中的toBeObservable() 并且看不到自定义参数。我也不明白为什么Notification 不是Object

版本:

  • rxjs:7.5.2
  • 茉莉花核:4.0.0
  • 茉莉花弹珠:0.8.4
  • 业力茉莉花:4.0.1

该脚本适用于 rxjs 6.6.7。

【问题讨论】:

    标签: rxjs jasmine karma-jasmine jasmine-marbles


    【解决方案1】:

    我认为新文档显示了新的 expectObservable:

    expectObservable(new BehaviorSubject(true).asObservable()).toBe(expected);
    

    在此处查看文档:https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/testing/marble-testing.md#marble-syntax

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-19
      • 2018-09-26
      • 2022-01-13
      • 1970-01-01
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      相关资源
      最近更新 更多