0

First let me say that I am fairly new to intern and Leadfoot API. What I am trying to do is iterate through an array of elements and perform an assertion on each of them. Here is my code:

'Alerts': function () {
        return this.remote 
        .get(require.toUrl(url))
        .setFindTimeout(timeout)
        .findById('alertsHeader')
        .click()
        .end()
        .findByClassName('_3WMFy')
        .findAllByCssSelector('div')
        .getVisibleText()
        .then(function(texts){
            assert.equal(texts, [ 'ALL', 'P1', 'P2', 'P3' ]);   

        });
    }

However, the test fails with the following output:

AssertionError: expected [ 'ALL', 'P1', 'P2', 'P3' ] to equal [ 'ALL', 'P1', 'P2', 'P3' ]

Can someone explain this error? Maybe I am missing something (as is often the case) but I stared at this for while, and I'm pretty sure those two are equal. So I purposely changed one line to make one of the elements not match and got the following error:

    AssertionError: expected [ 'ALL', 'P1', 'P2', 'P3' ] to equal [ 'ALL', 'P1', 'P2', 'P377' ]

  [
    0: "ALL",
    1: "P1",
    2: "P2",
E   3: "P377",
A   3: "P3",
    length: 4
  ]

My questions are, I am doing something wrong here, or this a bug? Is this the correct way to iterate these elements, or should I be doing something else? Is it possible to use a for loop here? What would be the best way to do this? Any help provided would be much appreciated!

Williz
  • 309
  • 1
  • 9
  • What do you think *assert* means? The dictionary says it means *"state a fact or belief confidently and forcefully."* In other words, in your second example you're stating a belief that *"`[ 'ALL', 'P1', 'P2', 'P3' ]` to equal `[ 'ALL', 'P1', 'P2', 'P377' ]`"* and wondering why your compiler is arguing with you? The error message is clear; it's telling you that your *assertion* is wrong. – autistic Aug 17 '17 at 18:27
  • Yes I understand that. That was not my question. I know that [ 'ALL', 'P1', 'P2', 'P3' ] does not equal [ 'ALL', 'P1', 'P2', 'P377' ] I put that example in there to show that it gave me a different output in the error message. My question was, why is it telling me [ 'ALL', 'P1', 'P2', 'P3' ] does not equal [ 'ALL', 'P1', 'P2', 'P3' ]? I found the answer in the link posted above, which is that I should be using deepEqual(). Thanks – Williz Aug 17 '17 at 21:22

0 Answers0