Is it possible to use Jasmine's toHaveBeenCalledWith matcher with a regular expression?

前端 未结 6 2057
囚心锁ツ
囚心锁ツ 2020-12-29 19:16

I have reviewed Jasmine\'s documentation of the toHaveBeenCalledWith matcher in order to understand whether it\'s possible to pass in a regular expression for an argument, i

6条回答
  •  庸人自扰
    2020-12-29 19:40

    Sometimes it is more readable to write it this way:

    spyOn(obj, 'method').and.callFake(function(arg1, arg2) {
        expect(arg1).toMatch(/bar/);
        expect(arg2).toMatch(/baz/);
    });
    obj.method('bar', 'baz');
    expect(obj.method).toHaveBeenCalled();
    

    It give more clear visibility of method arguments (instead of using array)

提交回复
热议问题