2

Is there a way in sinon-chai to test whether a string contains sub-strings in the specified order? Something like:

expect("Hello World, it's a lovely day!").to.contain.in.order("World", "day")

Similar to what the sinon-chai-in-order does for spy calls.

I am currently using a regexp matching similar to this:

expect(vm.$el.querySelector('table').textContent.replace(/\r?\n|\r/g, ''))
  .to.match(/.*A.*B.*D.*C.*/)

Originally, I was doing the following, but for I am not sure why it doesn't match across the newline:

expect(vm.$el.querySelector('table').textContent)
  .to.match(/.*A.*B.*D.*C.*/gm)

However these matches can be sometimes hard to read and readability is the reason I am using sinon-chai.

MartinTeeVarga
  • 10,478
  • 12
  • 61
  • 98
  • If you're using ES6, you could improve readability using [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals), like this: `expect('Jonathan Conway').to.match(new RegExp(``${firstName}.*${lastName}``))` – Jonathan Aug 07 '17 at 02:19

0 Answers0