From the course: JavaScript: Test-Driven Development (ES6)

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Using environment variables in testing

Using environment variables in testing - JavaScript Tutorial

From the course: JavaScript: Test-Driven Development (ES6)

Start my 1-month free trial

Using environment variables in testing

- So now we have our first passing integration test, which is great. However, I do want to point out that we're hard-coding our test database name into our production code, and this is definitely not what we want. The problem is if we switch over and instead hard-code our production database here, we wouldn't be able to test it effectively without switching over our test code to use the production database, which is also definitely not what we want. So what do we do here? The answer is to use environment variables. Some of you may be familiar with environment variables from working with dev and production environments, they allow you to pass in different values to your code depending on the environment your code is running in. So for example they allow you to do stuff like have different databases depending on whether your code is running in a production, development, or test environment. And that's exactly what we need…

Contents