Expect.toContains() with if ...else if...else
See original GitHub issuewant to differentiate some values from list into different different arrays like $ 1 B , $ 2 B , $ 100 M ,$ 300 M , $ 105 K , $ 205 K so i tried it with expect.toContain(‘’) method
var ele = element.all(by.css('.company-network-list__header__income.ng-scope .ng-binding.ng-scope'));
var b =[] , m=[], k=[];
ele.map(function(eachName) {
return eachName.getText().then(function(unSorted) {
if(expect(unSorted).toContain('B')){
var b = unSorted;
}
else if(expect(unSorted).toContain('M')){
var m = unSorted;
}
else{
var k = unSorted;
}
});
});
for 2 values …i tried with try catch
try{
expect(unSorted).toContain('B');
var b = unSorted;
}catch(e) {
var m = unSorted;
}
also this…
expect(unSorted).toContain('B').then(function(result) {
if(result){
var b= unSorted;
}else {
var m= unSorted;
}
});
Not working anything from these Can anyone please help me to solve this issue
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Expect - Jest
When you're writing tests, you often need to check that values meet certain conditions. expect gives you access to a number of "matchers" ......
Read more >How to make an expect statement be condition for if statement
I want to make it into an if statement that would the url as the condition. How could I do that? if(browser.driver.getCurrentUrl().toEqual(" ...
Read more >Untitled
An IF statement is a logical formula. ts jest cannot use import statement outside a module. describe("Suite", () => { it("test", ); prettify....
Read more >if...else - JavaScript - MDN Web Docs - Mozilla
The if...else statement executes a statement if a specified condition is truthy. If the condition is falsy, another statement in the ...
Read more >Expect · Jest
Everything else is truthy. .toBeUndefined() #. Use .toBeUndefined to check that a variable is undefined. For example, if you want to check ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You are right, missed the toContain() part… Use: if (unSorted.indexOf(‘B’) > -1);
Google will help you for future js queries 😉
@hitesh-jani
First, like you have on your post: “Make sure you are not asking a usage or debugging question. If you are, use StackOverflow, Google Group discussion list, or Gitter to get help.” this is a question not a protractor issue.
Trying to help you before this issue gets closed, I don’t think expect() should be used in if…else clauses… The expect() is an assertion. Picking your first example, I don’t understand why you define var b = [] and then in the if you redefine it with different type (var b = string). Also, you return eachName.getText() but don’t return anything inside your function(unSorted).
Give it a try this way:
Hope it helps and don’t forget to use StackOverflow for future questions.