Expect item in array

后端 未结 3 877
执念已碎
执念已碎 2020-12-04 01:18

One of my test expects an error message text to be one of multiple values. Since getText() returns a promise I cannot use toContain() jasm

3条回答
  •  自闭症患者
    2020-12-04 01:59

    To me, the work-around that you identified is the best solution. However, we should not forget that this is an asynchronous execution and you might want to consider Jasmine's asynchronous support.

    Then, your test will look like the following one:

    it('should check item is in array', function(done){ //Note the argument for callback
    
        // do your stuff/prerequisites for the spec here
    
        page.errorMessage.getText().then(function (text) {
            expect(["Unknown Error", "Connection Error"]).toContain(text);
            done(); // Spec is done! 
        });
    });
    

    Note: If you don't pass this done argument to the spec callback, it is going to run to completion without failures, but no assertions are going to be reported in the execution results for that spec (in other words, that spec will have 0 assertions) and it might lead to confusions.

提交回复
热议问题