Database calls with Ember Test

Can you make DB connections and queries (postgres) within an Ember Test js? Cheers, Huck

I think it’s possible with some configuring, but for the most part the recommended direction would be to use something like Mirage to mock a backend for your acceptance/application tests. The purpose of front-end tests in Ember is to test just the front-end code, so introducing an external database could add another point of failure and make the tests more brittle.

In general I’d say for scenarios where you want to do end-to-end testing you’d want to use a test framework that’s meant for that purpose. For example at my company we test our front-end code and accessibility with Ember tests and do full-stack tests with Selenium, etc in our CI environment.

One advantage of testing the front-end separately, in addition to what I mentioned above, is that Ember tests tend to be a lot faster and more lightweight.

Anyway, just my 2c. The short answer is “yes, theoretically it should work and I’m pretty sure I’ve seen other people mention doing it, but it’s not really recommended”.

Thanks! You see, I was using cucumberjs along with puppeteer/selenium, but I can’t get selenium to recognize the computed properties. If I could solve that, I’d be golden.

So my recommendation would be to use each type of test in a “stack” as it were:

  1. Ember Unit/Container tests (formerly called unit tests) for things like computed properties, controllers, utils, serializers, services, etc. These should be tested atomically and anything else that they use should be mocked.
  2. Ember Rendering tests (formerly called integration tests) for testing component rendering behavior
  3. Ember Application tests with fixtures or mirage for testing full page rendering, user workflows, etc
  4. Selenium/Pupeteer for full end-to-end tests

I know it’s kind of annoying to have two different testing frameworks but they kinda have different scopes and testing stuff like CPs should be pretty low level and isolated from the greater application.