I’m using the delightful chai-string to test responses that should start with a known string. When working with promises, and specifically, the awesome chai-as-promised, the order in which you use the chai plugins is important, regardless if you have one file or multiple!

I first came across this in chai-string issue #9. Since then I have added more test files and had tests that should.eventually.startWith('some string') fail. Oddly, when I ran the test individually, or ran all the tests in a single file, all completed successfully. It was not until I ran tests in multiple files that these tests failed. It turned out chai.use(require('chai-as-promised')) existed in a file loaded prior to tests having chai.use(require('chai-string')).

My solution was to create a file that loaded the plugins in the appropriate order and have that run prior to other tests. This is accomplished by naming the file such that it comes first alphabetically. For this scenario, I called the file test_!initialization.js. It consisted of the following:

  1. I must say it was hard to find your website in search results.

    You write interesting articles but you should rank
    your blog higher in search engines. If you don’t know how to do it search on youtube:
    how to rank a website Marcel’s way

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">